温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ElasticSearch for Modify your Data

发布时间:2020-06-15 15:05:51 来源:网络 阅读:438 作者:cqvienet 栏目:开发技术

一、Updating Documents

This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '

{

"doc":{"name":"Jane Doe"}

}'

This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe" and at the same time add an age field to it:

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '

{

"doc":{"name":"Jane Doe","ages":20}

0}'

Elasticsearch支持通过脚本修改文档信息

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d ' {  "script" : "ctx._source.ages += 5" }'

OR

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '

{

 "script": {

     "inline":{ctx._source.ages+=age},

     "params":{

      "age":20     

}   

}

}'

除了_source字段,可以通过ctx来获得_index、_type、_id、_version、_parent、_timestamp、_ttl等字段信息

也可以利用srcipt添加字段信息

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d  '

{

  "script":"ctx._source.name_of_new_field=\"value_of_new_field\""

}'

也可以利用srcipt移除字段信息

curl -XPOST '192.168.56.101:9200/customer/external/1/_update?pretty' -d '

{

  "script":"ctx._source.remove(\"name_of_field\")"

}'


二、Delting Documents

Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2

curl -XDELETE '192.168.56.101:9200/customer/external/2?pretty'

三、Batch Processing

As a quick example, the following call indexes two documents (ID 1 - John Doe and ID 2 - Jane Doe) in one bulk operation:

curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'

This example updates the first document (ID of 1) and then deletes the second document (ID of 2) in one bulk operation:

curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI