栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【elasticsearch】msearch查询

【elasticsearch】msearch查询

参考博客
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
    }
  ]
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/673849.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号