博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Elasticsearch之CURL命令的mget查询
阅读量:6660 次
发布时间:2019-06-25

本文共 2354 字,大约阅读时间需要 7 分钟。

 

 

 

   我这里,

 

 

 

    再,创建一个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]$

 

 

 

  

  更多,请见

 

转载地址:http://bkxto.baihongyu.com/

你可能感兴趣的文章
Hbase 学习(十一)使用hive往hbase当中导入数据
查看>>
Using SmartAssembly with MSBuild
查看>>
关于前端本地压缩图片,兼容IOS/Android/PC且自动按需加载文件之lrz.bundle.js
查看>>
CSS:@font-face的使用方法
查看>>
goEasy消息推送,pushlet 向特写用户实时推送
查看>>
Linux下的snmpd.conf配置说明
查看>>
平均寻道时间的定义
查看>>
9号团队-团队任务4:每日立会(2018-12-5)
查看>>
搭建maven支持的web工程的步骤
查看>>
js进阶ajax读取json数据(ajax读取json和读取普通文本,和获取服务器返回数据(链接)都是一样的,在url处放上json文件的地址即可)...
查看>>
常见的25个python面试问答
查看>>
博客迁移到http://pengliu.cf
查看>>
C# 之泛型详解
查看>>
Scrapy+WordCloud--博客园前3000名博友全部文章抓取
查看>>
将包含中文的数组按拼音首字母排序
查看>>
C#语言入门
查看>>
密码只能输入字母+数字不能包含特殊字符的校验规则
查看>>
python基础2
查看>>
Linux查看操作系统版本的几种方式
查看>>
【HDU 1402】A * B Problem Plus(FFT)
查看>>