Elasticsearch 入门 - Modifying Your Data

index/update/delete 均有大概1秒的缓存时间

Indexing/Replacing Documents

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'

replace/reindex:

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'

Index a new document with and ID of 2:

curl -X PUT "localhost:9200/customer/_doc/2?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'

Index a document without an explicit ID:

curl -X POST "localhost:9200/customer/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'

Updating Documents

Elasticsearch 的更新操作并非原位更新数据,不管什么时候更新操作都是删除旧文档后再索引新的文档。
将ID为1的文档name字段更新为 "Jane Doe":

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "doc": { "name": "Jane Doe" }
}
'

将ID为1的文档name字段更新为 "Jane Doe"的同时添加一个age字段:

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "doc": { "name": "Jane Doe", "age": 20 }
}
'

更新操作能够执行简单的脚本,例如使用脚本将age加5:

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
  "script" : "ctx._source.age += 5"
}
'

其中 ctx._source 指向当前需要被更新的文档。

Deleting Documents

删除ID为2的文档:

curl -X DELETE "localhost:9200/customer/_doc/2?pretty"

转载于:https://www.cnblogs.com/gebilaowangpython/p/10423016.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值