欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

elasticSearch 检索 mget 用法示例

程序员文章站 2022-07-02 23:04:47
总结一下自己看elsaticsearch 文档,对于mget用法的实践:需要说明一下,这里必须是ids或者docs,否则会报如下的异常信息:异常信息如下:{ "error": { "root_cause": [ { "type": "parsing_exception", "reason": "unknown key [policyNo] for a START_ARRAY, expected [docs] or [ids]",...

总结一下自己看elsaticsearch 文档,对于mget用法的实践:

需要说明一下,这里必须是ids或者docs,否则会报如下的异常信息:

异常信息如下:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "unknown key [policyNo] for a START_ARRAY, expected [docs] or [ids]",
        "line": 2,
        "col": 14
      }
    ],
    "type": "parsing_exception",
    "reason": "unknown key [policyNo] for a START_ARRAY, expected [docs] or [ids]",
    "line": 2,
    "col": 14
  },
  "status": 400
}
GET index_name/type_name/_mget
{
  "ids":["10000000743880","10000000745270"]
}

返回的结构如下:

{
  "docs": [
    {
      "_index": "index_name",
      "_type": "typename",
      "_id": "10000000743880",
      "_version": 1,
      "found": true,
      "_source": {
      	//此处是你查找的文档的具体内容
      }
    }
  ]
 }
GET index_name/type_name/_mget
{
  "docs":[
    {
      "_id":"10000000743880"
    }, 
    {
      "_id":"10000000745270"
    }
  ]
}

此处使用mget做查询,使用关键字docs,

GET index_name/_mget
{
  "docs":[
    {
      "_type":"type_name",
      "_id":"10000000743880"
    }, 
    {
      "_type":"type_name",
      "_id":"10000000745270"
   }
  ]
}
GET /_mget
{
  "docs":[
    {
      "_index":"index_name",
      "_type":"type_name",
      "_id":"10000000743880"
    }, 
    {
      "_index":"index_name",
      "_type":"type_name",
      "_id":"10000000745270"
   }
  ]
}
GET /_mget
{
  "docs":[
    {
      "_index":"index_name",
      "_type":"typeA_name",
      "_source":false,
      "_id":"10000000743880"
    }, 
    {
      "_index":"index_name",
      "_type":"typeB_name",
       "_source":["policyNo","policyRelationNo"],
      "_id":"10000000745270"
   },
   {
      "_index":"index_name",
      "_type":"typeC_name",
       "_source":{
         "include":["policyNo","policyRelationNo","policyHolder"],
         "exclude":["policyHolder.birthday"]
       },
      "_id":"10000000742932"
   }
  ]
}

本文地址:https://blog.csdn.net/u012934325/article/details/107301914