I have an index with documents like the following:
[
{
"field1": "foo",
"field2": "bar"
},
...
]
Basically what I need is to add a field field3
to every document with field1
and field2
concatenated and separated by a semicolon, like this:
[
{
"field1": "foo",
"field2": "bar",
"field3": "foo;bar"
},
...
]
Is there any way to add the new column to all my documents copying values from the other fields automatically?
Use following query then:
POST /my_index/my_type/_update_by_query
{
"query": {
"match_all": {}
},
"script": "ctx._source.field3 = ctx._source.field1 + ';' + ctx._source.field2"
}
Make sure to enable scripting
in elasticsearch.yml
and restart ES.
This requires no reindexing
Hope this works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With