文档管理
一、新建文档(insert–PUT/POST)
文档在es中,比lucene的文档结构,多了一个叫做type的概念,一个index索引可以有多个不同的type类型,每个type类型中的document结构一致;对比数据库,type相当于表格
文档的数据结构要在url中体现,是以 -d 为选项,包含,使用json字符串完成文档结构的组合"
# article表示index01中的类型,1表示article中文档的id值,需要保证全局唯一
[root@localhost ~]# curl -XPUT -d '{"id": 1, "title": "es简介", "content": "es好用 好用真好用"}' http://192.168.47.102:9200/index01/article/1
二、获取文档
文档是具有id的,可以通过这个文档id获取文档对象的数据,返回内容包含json字符串,json字符串信息
1、获取单个文档
# 获取单个文档
[root@localhost ~]# curl -XGET http://192.168.47.102:9200/index01/article/1
# 返回内容
{"_index":"index01","_type":"article","_id":"1","_version":1,"found":true,"_source":{"id": 1, "title": "es简介", "content": "es好用好用真好用"}}
2、获取多个文档
# 获取多个文档命令
[root@localhost ~]# curl -XGET -d '{"docs": [{"_index": "index01", "_type": "article", "_id": "1"}, {"_index": "index01", "_type": "article", "_id": "2"}]}' http://192.168.47.102:9200/_mget
# 返回内容如下
{"docs":[{"_index":"index01","_type":"article","_id":"1","_version":1,"found":true,"_source":{"id": 1, "title": "es简介", "content": "es好用好用真好用"}},{"_index":"index01","_type":"article","_id":"2","_version":1,"found":true,"_source":{"id": 1, "title": "贵永康简介", "content": "贵永康是真的骚"}}]}
3、删除文档
Delete删除,指定删除id值为*的一个文档
# 删除index01索引下,type为article的,id为2的文档
[root@localhost ~]# curl -XDELETE http://192.168.47.102:9200/index01/article/2