Is it possible to update some specific fields value in elasticsearch with out overwriting other fields. ?
If you would like to update the existing field value only then you must try this solution:
POST IndexName/_update_by_query
{
"script": {
"source": """
if (ctx._source?.Field != null)
{
ctx._source.remove('Field');
ctx._source.put('Field', 'Value');
}
""",
"lang": "painless"
},
"query": {
"terms": {
"_id": [
1 (Replace with Document ID)
]
}
}
}
If you would like to add new field with value then you must try this solution:
POST IndexName/_update_by_query
{
"script": {
"source": """
if (ctx._source?.NewField == null)
{
ctx._source.hf.put('NewField', 'Value');
}
""",
"lang": "painless"
},
"query": {
"terms": {
"_id": [
1 (Replace with Document ID)
]
}
}
}