python 批量搜索ES
from elasticsearch import Elasticsearch
import json
def run():
es = Elasticsearch(hosts=["https://esip:9200/"],
http_auth=('user', 'passwd'))
body = [
{"index":"dwt_tianshu_index","type":"_doc"},
{"query": {"match": {"name": "安亦茶麸养发馆"}},"size":1},
{"index": "dwt_tianshu_index", "type": "_doc"},
{"query": {"match": {"name": "顺达快运(印山北路)"}}, "size": 1},
{"index": "dwt_tianshu_index", "type": "_doc"},
{"query": {"match": {"name": "asdfasdfa"}}, "size": 1}
]
request_body=''
for i in body:
request_body += "%s \n" % json.dumps(i,ensure_ascii=False)
print(request_body)
res = es.msearch(body=request_body)
print(json.dumps(res,ensure_ascii=False))
if __name__ == '__main__':
run()