ElasticSearch for Modify your Data

Source: Internet
Author: User

I. Updating Documents

This example shows how to update we 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 we 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 support for modifying document information through scripting

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

}

}

}‘

In addition to the _source field, CTX can be used to obtain _index, _type, _id, _version, _parent, _timestamp, _ttl, and other field information

You can also use Srcipt to add field information

Curl-xpost ' 192.168.56.101:9200/customer/external/1/_update?pretty '-d '

{

"Script": "Ctx._source.name_of_new_field=\" value_of_new_field\ ""

}‘

You can also use Srcipt to remove field information

Curl-xpost ' 192.168.56.101:9200/customer/external/1/_update?pretty '-d '

{

"Script": "Ctx._source.remove (\" name_of_field\ ")"

}‘


Second, 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 '

Third, Batch processing

As a quick example, the following call indexes both 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 "}}


ElasticSearch for Modify your Data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.