码迷,mamicode.com
首页 > Windows程序 > 详细

增删改查 elasticsearch中的文档API 的使用

时间:2016-05-13 15:38:19      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:增删改查 elasticsearch中的文档 api

文档为何物?一个对象 就相当于mysql的一个record记录


参考:

http://www.learnes.net/data/README.html


curl 192.168.100.10:9200?preety
curl 192.168.100.10:9200/_count?pretty


shell 中的curl的用法

-X 指定请求方法默认是  -XGET

-i 返回数据的时候,也一并返回请求结果

-d 发送的数据



这个返回值意味着我们的索引请求已经被成功创建,其中还包含了_index, _type以及_id的元数据,以及一个新的元素_version

_index 名词就是相当于数据库中库

_type 相当于数据库中的表

_id 就是id(可以自己指定也以自增)


_index 和 _type 和 _id 三者组成elasticsearch存储中的数据的唯一


创建一条

curl -XPUT 192.168.100.10:9200/website/blog/123 -d ‘{
"title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2016/01/01"
 }‘



 可以看到搜索到了当时创建的文档

[root@master ~]# curl 192.168.100.10:9200/website/blog/123?pretty 
{
  "_index" : "website",
  "_type" : "blog",
  "_id" : "123",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "title" : "My first blog entry",
    "text" : "Just trying this out...",
    "date" : "2014/01/01"
  }
}

每找到的情况:

[root@master ~]# curl 192.168.100.10:9200/website/blog/1235?pretty
{
  "_index" : "website",
  "_type" : "blog",
  "_id" : "1235",
  "found" : false
}


_source 是文档的内容。可以指定值返回文档指定的字段

[root@master ~]# curl -i -XGET "192.168.100.10:9200/logstash-2016.05.12/syslog/AVSlIBy3bzztddJUaGzh?_source=file,meesage&pretty"
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 185
{
  "_index" : "logstash-2016.05.12",
  "_type" : "syslog",
  "_id" : "AVSlIBy3bzztddJUaGzh",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "file" : "/var/log/messages"
  }
}



一次获取多个文档_mget

[root@master ~]# curl -i -XGET 192.168.100.10:9200/logstash-2016.05.12/syslog/_mget?pretty -d ‘{"ids": [ "2",  "1"]}‘  
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 230
{
  "docs" : [ {
    "_index" : "logstash-2016.05.12",
    "_type" : "syslog",
    "_id" : "2",
    "found" : false
  }, {
    "_index" : "logstash-2016.05.12",
    "_type" : "syslog",
    "_id" : "1",
    "found" : false
  } ]
}



本文出自 “崔德华运维打工从业路” 博客,请务必保留此出处http://cuidehua.blog.51cto.com/5449828/1772867

增删改查 elasticsearch中的文档API 的使用

标签:增删改查 elasticsearch中的文档 api

原文地址:http://cuidehua.blog.51cto.com/5449828/1772867

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