Skip to content

Instantly share code, notes, and snippets.

@thinog
Created October 6, 2020 03:20
Show Gist options
  • Save thinog/221963958d9820da493e1b708329253d to your computer and use it in GitHub Desktop.
Save thinog/221963958d9820da493e1b708329253d to your computer and use it in GitHub Desktop.
Elasticsearch - Updating nested fields
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