Elasticsearch文档描述了一种为 msearch API 查询构建简单查询体的方法。但是,如果您使用聚合,则使用 curl 或任何版本的 elasticsearch-py 库都不再适用。Github 对应票证。示例查询:
{
"query": {
"filtered": {
"filter": { "term": {"applicationType":"myapptype"} },
"query": {"match": {"search_key": "my_key_value"}}
}
},
"aggs": {"client": {"terms": {"field": "client"}}},
"size": 0
}
Python代码:
es = Elasticsearch()
es.msearch(body=[
{"index": "index20150315"},
{"query": {'filtered': {'filter': {'term': {'applicationType': 'myapptype'}}, 'query': {'match': {'search_key': 'my_key_value'}}}}, 'aggs': {'client': {'terms': {'field': 'client'}}}, 'size': 0}
])
输出如下:
{u'responses': [{u'error': u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[BRYrrx8dR4i-ukxlXbuNEw][index20150315][1]: RemoteTransportException[[i-1f30c5fb][inet[/10.101.2.234:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][1]: query[filtered(search_key:my_key_value)->cache(applicationType:myapptype)],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filtered": {"filter": {"term": {"applicationType": "myapptype"}}, "query": {"match": {"search_key": "my_key_value"}}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "aggs"]; }{[BRYrrx8dR4i-ukxlXbuNEw][index20150315][2]: RemoteTransportException[[i-1f30c5fb][inet[/10.101.2.234:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][2]: query[filtered(search_key:my_key_value)->cache(applicationType:myapptype)],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filtered": {"filter": {"term": {"applicationType": "myapptype"}}, "query": {"match": {"search_key": "my_key_value"}}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "aggs"]; }{[No9GT_PtQh6XoOvfz5uTmw][index20150315][0]: RemoteTransportException[[i-1d30c5f9][inet[/10.101.2.237:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][0]: query[filtered(search_key:my_key_value)->cache(applicationType:myapptype)],from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filtered": {"filter": {"term": {"applicationType": "myapptype"}}, "query": {"match": {"search_key": "my_key_value"}}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT "aggs"]; }]'}]}
有没有人设法使 msearch API 与包含聚合的查询一起工作?