How to concatenate a string on elastic search How to concatenate a string on elastic search elasticsearch elasticsearch

How to concatenate a string on elastic search


In addition to what @jhilden said , we can indeed update an specific field in a ES document. But you need to enable scripting first.

Directly from the documentation :

#Index a documentcurl -XPUT localhost:9200/test/type1/1 -d '{    "counter" : 1,    "tags" : ["red"]}'#Increase the count using inline scripting    curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{        "script" : {            "inline": "ctx._source.counter += count",            "params" : {                "count" : 4            }        }    }'#Add a new fieldcurl -XPOST 'localhost:9200/test/type1/1/_update' -d '{    "script" : "ctx._source.name_of_new_field = \"value_of_new_field\""}'

You can also update by query in case that you don't know the id of the document or if you want to do a bulk update.

POST /twitter/_update_by_query{  "script": {    "inline": "ctx._source.likes++"  },  "query": {    "term": {      "user": "kimchy"    }  }}

More details of both concepts:

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-update.html

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-update-by-query.html

More information about inline scripting :

https://www.elastic.co/guide/en/elasticsearch/reference/2.4/modules-scripting.html


If I understand your problem correctly you want to UPDATE a record in ElasticSearch. There is no way in ES to do a partial update. What I mean is, there is no equivalent to this:

UPDATE tbl1SET col1 = 'I am updating only 1 column'WHERE id = 123

In ElasticSaerch we update a record by:

  1. GET the record you are looking for
  2. update the record
  3. POST the FULL, updated, record back to ElasticSearch specifying the existing _id field.

This will overwrite the old record, something you can verify by looking at the _version property.