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 を動作させることができた人はいますか?