zoukankan      html  css  js  c++  java
  • Elasticsearch之CURL命令的mget查询

       我这里,

        再,创建一个zhouls2的索引库。

    [hadoop@master elasticsearch-2.4.0]$ curl -XPUT 'http://master:9200/zhouls2/'
    {"acknowledged":true}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 

      得到

     

       在新创建的索引库zhouls2里,添加一条数据进去。

    [hadoop@master elasticsearch-2.4.0]$ curl -XPOST http://master:9200/zhouls2/user/1 -d '{"name" : "lucy" , "age" : 18}'  
    {"_index":"zhouls2","_type":"user","_id":"1","_version":1,"_shards":{"total":2,"successful":2,"failed":0},"created":true}[hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 
    [hadoop@master elasticsearch-2.4.0]$ 

       得到

     

       如下,是我用mget命令,为大家演示,通过xmget命令来获取多个文档

    [hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/_mget?pretty -d '{"docs": [{"_index":"zhouls" ,"_type":"user" ,"_id":2 ,"_source":"name"} ,{"_index":"zhouls2" , "_type":"user" ,"_id":1}]}'
    {
      "docs" : [ {
        "_index" : "zhouls",
        "_type" : "user",
        "_id" : "2",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "john"
        }
      }, {
        "_index" : "zhouls2",
        "_type" : "user",
        "_id" : "1",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "lucy",
          "age" : 18
        }
      } ]
    }
    [hadoop@master elasticsearch-2.4.0]$ 

      如果我们需要的文档在同一个_index或者同一个_type中,我们就可以在URL中指定一个默认的/_index或者_index/_type。

    [hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/_mget?pretty -d '{"docs": [{"_id":1} ,{"_id":2}] }'
    {
      "docs" : [ {
        "_index" : "zhouls",
        "_type" : "user",
        "_id" : "1",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "john",
          "age" : 28
        }
      }, {
        "_index" : "zhouls",
        "_type" : "user",
        "_id" : "2",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "john",
          "age" : 28
        }
      } ]
    }
    [hadoop@master elasticsearch-2.4.0]$ 

      如果我们的文档拥有相同的_index以及_type,直接在请求中添加ids的数组即可

    [hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/_mget?pretty -d '{"ids":["1" ,"2"]}'
    {
      "docs" : [ {
        "_index" : "zhouls",
        "_type" : "user",
        "_id" : "1",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "john",
          "age" : 28
        }
      }, {
        "_index" : "zhouls",
        "_type" : "user",
        "_id" : "2",
        "_version" : 1,
        "found" : true,
        "_source" : {
          "name" : "john",
          "age" : 28
        }
      } ]
    }
    [hadoop@master elasticsearch-2.4.0]$ 

      

      更多,请见

    Elasticsearch增删改查 之 —— mget多文档查询

  • 相关阅读:
    SPOJ 8222 NSUBSTR
    bzoj千题计划284:bzoj2882: 工艺
    bzoj千题计划283:bzoj4516: [Sdoi2016]生成魔咒(后缀数组)
    bzoj千题计划282:bzoj4517: [Sdoi2016]排列计数
    bzoj千题计划281:bzoj4558: [JLoi2016]方
    bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
    bzoj千题计划279:bzoj4591: [Shoi2015]超能粒子炮·改
    bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
    bzoj千题计划277:bzoj4513: [Sdoi2016]储能表
    bzoj千题计划276:bzoj4515: [Sdoi2016]游戏
  • 原文地址:https://www.cnblogs.com/zlslch/p/7101559.html
Copyright © 2011-2022 走看看