ElasticSearch——文档管理

文档管理

一、新建文档(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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值