Created
October 6, 2020 03:20
-
-
Save thinog/221963958d9820da493e1b708329253d to your computer and use it in GitHub Desktop.
Elasticsearch - Updating nested fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST my-index/_update_by_query | |
{ | |
"script": { | |
// "source" after v5.6, "inline" before | |
"source": """ | |
for (item in ctx._source.nested_items) { | |
for(param in params.new_values) { | |
if (item.category == param.category) { | |
item.description = param.description; | |
} | |
} | |
} | |
""", | |
"lang": "painless", | |
"params": { | |
"new_values": [ | |
{ | |
"category": 1, | |
"description": "Category 1 description" | |
}, | |
{ | |
"category": 2, | |
"description": "Category 2 description" | |
}, | |
{ | |
"category": 3, | |
"description": "Category 3 description" | |
} | |
] | |
} | |
}, | |
"query":{ | |
"term": { | |
"_id": "1" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment