Updating existing documents in elasticsearch

Is it possible to add additional fields to existing documents in elasticsearch?

I indexed, for example, the following document:

{ "user":"xyz", "message":"for increase in fields" } 

Now I want to add another 1 ie date field to it:

 { "user":"xyz", "message":"for increase in fields", "date":"2013-06-12" } 

How can I do that?

+4
source share
2 answers

To check elastic search update

The update API also supports the transfer of a partial document (starting from 0.20) that will be merged into an existing document (simple recursive merge, internal merge of objects, replacement of the main "keys / values" and arrays)

Solr 4.0 also supports partial updates. Check Link

+9
source

This can be done using a partial update (provided that the document has identifier 1):

 curl -XPOST 'http://localhost:9200/myindex/mytype/1/_update' -d ' { "doc" : { "date":"2013-06-12" } }' 

Then request a document:

 curl -XGET 'http://localhost:9200/myindex/mytype/_search?q=user:xyz' 

You should see something like:

 "_id":"1", "_source: { { "user":"xyz", "message":"for increase in fields", "date":"2013-06-12" } } 
+3
source

Source: https://habr.com/ru/post/1485973/


All Articles