Tech 기록지/Elastic Stack
[ElasticStack-27] Elasticsearch msearch (with Python)
Lio Grande
2020. 7. 23. 11:23
Elasticsearch로 msearch를 수행할떄는 다음과 같은 패턴으로 작성을 하게 된다.
GET _msearch
{"index": "index1"}
{"query": {"match_all": {}}}
{"index": "index2"}
{"query": {"match_all": {}}}
{"index": "index3"}
{"query": {"match_all": {}}}
참고 링크
만약 위와 같은 쿼리를 Elasticsearch-python module을 활용하여 수행하고 싶다면 다음과 같이 작성하자.
from elasticsearch import Elasticsearch
es = Elasticsearch()
body = [ {"index": "index1"},
{"query": {"match_all": {}}},
{"index": "index2"},
{"query": {"match_all": {}}},
{"index": "index3"},
{"query": {"match_all": {}}}
]
res = es.msearch(body=body)
print(res)
msearch 결과를 cmd를 통해 확인 가능하다.