As @joe suggested you need to do it at ingest time, however, you can create a pipeline as a suggestion. I did a local test using the append and join processors. First I appended field1's value and field2's value, then use the join processor on the array created with name append_fields.
I ingested the following values in the index "append_index",
"field1" : "value1",
"field2" : "value2"
"field1": "value10",
"field2": "value11"
I suggest you create the following pipeline(append_values) and then run it using the _update_by_query
:
PUT _ingest/pipeline/append_values
{
"processors": [
{
"append": {
"field": "append_fields",
"value": [
"{{field1}}",
"{{field2}}"
]
}
},
{
"join": {
"field": "append_fields",
"separator": ""
}
}
]
}
To use a pipeline in the _update__by_query
, use the following:
POST append_index/_update_by_query?pipeline=append_values
The response would be:
"hits" : [
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "_9ovaHQBsTCl1BZv7qhZ",
"_score" : 1.0,
"_source" : {
"field1" : "value1",
"append_fields" : "value1value2",
"field2" : "value2"
}
},
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "AdovaHQBsTCl1BZv9ak1",
"_score" : 1.0,
"_source" : {
"field1" : "value10",
"append_fields" : "value10value11",
"field2" : "value11"
}
}
]
Links:
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/append-processor.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/join-processor.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/pipeline.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html
Hope my suggestion helps :)
If you need help to understand what the append processor do, here is the output of executing the append processor without using the join processor:
"hits" : [
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "G9o9aHQBsTCl1BZvMcv6",
"_score" : 1.0,
"_source" : {
"field1" : "value1",
"append_fields" : [
"value1",
"value2"
],
"field2" : "value2"
}
},
{
"_index" : "append_index",
"_type" : "_doc",
"_id" : "edo9aHQBsTCl1BZvP8vT",
"_score" : 1.0,
"_source" : {
"field1" : "value10",
"append_fields" : [
"value10",
"value11"
],
"field2" : "value11"
}
}
]