Elasticsearch with python:查询特定字段

Noa*_*oam 2 python elasticsearch

我正在使用 python 的 elasticsearch 模块连接和搜索我的 elasticsearch 集群。

在集群中,我的索引中的字段之一是“消息”——我想从 python 查询我的弹性,以获取此“消息”字段中的特定值。

这是我的基本搜索,它只返回特定索引的所有日志。

    es = elasticsearch.Elasticsearch(source_cluster)
    doc = {
        'size' : 10000,
        'query': {
            'match_all' : {}
        }
    }
res = es.search(index='test-index', body=doc, scroll='1m')
Run Code Online (Sandbox Code Playgroud)

我应该如何更改此查询,以便在“消息”字段中找到带有“移动”一词的所有结果?

从 Kibana 执行此操作的等效查询是:

_index:test-index && message: moved

谢谢,

诺姆

Val*_*Val 7

您需要使用match查询。尝试这个:

doc = {
    'size' : 10000,
    'query': {
        'match' : {
            'message': 'moved'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)