Reputation: 3427
All of our ElasticSearch documents contain a field called Categories
which contains a string of comma-separated values. The length of each value between the commas is 5 characters, and the field can be anywhere from 1 to 12 5-character values.
I need to run a query against the index which says append ,ABCDE
to the end of Categories
field of all documents, unless the field already contains the value ABCDE
in it, in which case do not append anything to the field.
Upvotes: 0
Views: 1694
Reputation: 12830
You can use ElasticSearch _update_by_query like below
POST my_index/my_type/_update_by_query
{
"query": {
"bool": {
"must_not": [
{
"match": {
"Categories": "ABCDE"
}
}
]
}
},
"script": {
"inline": "ctx._source.Categories += ', ABCDE'",
"lang": "painless"
}
}
The above query will append string ', ABCDE'
to Categories if Categories doesn't contains the term ABCDE
Upvotes: 2