码迷,mamicode.com
首页 > 其他好文 > 详细

elastic(6) mget

时间:2018-02-01 10:39:27      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:first   ocs   uid   lib   需要   _id   com   div   个数   

转自:https://www.cnblogs.com/zhaijunming5/p/6424800.html

GET /library/books/1

技术分享图片
{
   "_index": "library",
   "_type": "books",
   "_id": "1",
   "_version": 1,
   "found": true,
   "_source": {
      "title": "Elasticsearch:the definitive guide",
      "name": {
         "first": "zachary",
         "last": "tong"
      },
      "publish_date": "2017-02-19",
      "price": "49.99"
   }
}
技术分享图片

GET /library/books/2

技术分享图片
{
   "_index": "library",
   "_type": "books",
   "_id": "2",
   "_version": 1,
   "found": true,
   "_source": {
      "title": "Elasticsearch:the definitive guide",
      "name": {
         "first": "zachary",
         "last": "tong"
      },
      "publish_date": "2017-02-19",
      "price": "59.99"
   }
}
技术分享图片

multi get

多字段查询可以设置多个文档查询条件,每个查询条件在结构上都比较类似

技术分享图片
GET /_mget
{
  
    "docs": [
      {
      "_index" : "library",
      "_type"  :  "books",
      "_id"    :  "1"
    },
    {
      "_index" : "library",
      "_type"  : "books",
      "_id"    : "2"
    }
    ]
  
  
}
技术分享图片

当然,在查询条件中,body中_index字段也可以放在查询字符串中

技术分享图片
GET /library/_mget
{
  
    "docs": [
      {
      
      "_type"  :  "books",
      "_id"    :  "1"
    },
    {
      
      "_type"  : "books",
      "_id"    : "2"
    }
    ]
  
  
}
技术分享图片

对于type也是一样:

技术分享图片
GET /library/books/_mget
{
  
    "docs": [
      {
      "_id"    :  "1"
    },
    {
      "_id"    : "2"
    }
    ]
}
技术分享图片

如果索引和类型都放在查询URL中,那么字段ID就可以放在一个数组中:

GET /library/books/_mget
{
  "ids" : ["1","2"]
}

如果想要查询不通类型的相同ID,就需要指定类型名称

技术分享图片
GET /test/_mget/
{
  "docs" : [
        {
            "_type":"typeA",
            "_id" : "1"
        },
        {
            "_type":"typeB",
            "_id" : "1"
        }
    ]
}
#这个例子不适用上面的测试数据
技术分享图片

Fields过滤

fields过滤是获取指定的字段

代码

技术分享图片
GET /_mget 
{
  "docs" : [
      {
        "_index":"library",
        "_type" : "books",
        "_id"   : "1",
        "fields" : ["publish_date","price"]
      },
      {
        "_index":"library",
        "_type" : "books",
        "_id"   : "2",
        "fields" : ["publish_date","price"]
      }
    ]
  
}
技术分享图片

结果

技术分享图片
{
   "docs": [
      {
         "_index": "library",
         "_type": "books",
         "_id": "1",
         "_version": 1,
         "found": true,
         "fields": {
            "publish_date": [
               "2017-02-19"
            ],
            "price": [
               "49.99"
            ]
         }
      },
      {
         "_index": "library",
         "_type": "books",
         "_id": "2",
         "_version": 1,
         "found": true,
         "fields": {
            "publish_date": [
               "2017-02-19"
            ],
            "price": [
               "59.99"
            ]
         }
      }
   ]
}

elastic(6) mget

标签:first   ocs   uid   lib   需要   _id   com   div   个数   

原文地址:https://www.cnblogs.com/guxiaobei/p/8397534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!