参考博客
https://blog.csdn.net/Conquer__EL/article/details/103746122
""" kibana
PUT blog/_doc/1
{
"name":"python 官网"
}
PUT blog/_doc/2
{
"name":"java 学习"
}
......
PUT blog/_doc/5
{
"name":"python 视频"
}
# 查询
POST /_msearch
{"index":"blog"}
{"query":{"match":{"name":"python"}}}
{"index":"blog"}
{"query":{"match":{"name":"java"}}}
"""
import json
from elasticsearch import Elasticsearch
es = Elasticsearch(["127.0.0.1:9200"])
a = [{"index": "blog"}, {"query": {"match": {"name": "python"}}}]
b = [{"index": "blog"}, {"query": {"match": {"name": "java"}}}]
search_body = []
search_body.extend(a)
search_body.extend(b)
res = es.msearch(index="blog", body=search_body)
print(json.dumps(res))
返回结构如下
{
"took": 2,
"responses": [
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [
{
"_index": "blog",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"name": "python 学习"
}
},
{
"_index": "blog",
"_type": "_doc",
"_id": "3",
"_score": 0.2876821,
"_source": {
"name": "python 官网"
}
},
{
"_index": "blog",
"_type": "_doc",
"_id": "4",
"_score": 0.2876821,
"_source": {
"name": "python 编码"
}
},
{
"_index": "blog",
"_type": "_doc",
"_id": "5",
"_score": 0.2876821,
"_source": {
"name": "python 视频"
}
}
]
},
"status": 200
},
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.3862942,
"hits": [
{
"_index": "blog",
"_type": "_doc",
"_id": "2",
"_score": 1.3862942,
"_source": {
"name": "java 学习"
}
}
]
},
"status": 200
}
]
}