Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating existing documents in elasticsearch

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

I indexed for instance the following document:

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

Now I want to add 1 more field to it i.e date:

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

How can this be done?

like image 341
Lav Avatar asked Dec 15 '22 09:12

Lav


2 Answers

For Elastic Search Check update

The update API also support passing a partial document (since 0.20), which will be merged into the existing document (simple recursive merge, inner merging of objects, replacing core “keys/values” and arrays)

Solr 4.0 also supports partial updates. check Link

like image 138
Jayendra Avatar answered Jan 08 '23 08:01

Jayendra


This can be done with a partial update (assuming the document has an ID of 1):

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

Then query the 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"
        }
    }
like image 34
Aaron Avatar answered Jan 08 '23 09:01

Aaron