_update_by_query column.column

I have this example mapping.
I need to update the field "shirt.color"

mapping
{
"shirts" : {
"mappings" : {
"properties" : {
"shirt" : {
"properties" : {
"brand" : {
"type" : "keyword"
},
"color" : {
"type" : "keyword"
},
"model" : {
"type" : "keyword"
}
} }, "tienda" : { "type" : "keyword" } } } } }`

data
{
"_index" : "shirts",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"tienda" : "mall",
"shirt.brand" : "gucci",
"shirt.color" : "red",
"shirt.model" : "slim"
}
}

I have tried this way

POST shirts/_update_by_query
POST shirts/_update_by_query?conflicts=proceed
{
"script": {
"inline": "ctx._source.shirt.color = params",
"lang": "painless",
"params": {"shirt.color" : "blue"}
},
"query": {
"bool": {
"filter": [ { "term": { "tienda": "mall" }}
]
}
}
}

but it does not work

error
image

Can you try replacing inline to source?

yes, I have the same error

Need to troubleshoot...

Try removing the params and update with the value directly.
"inline": "ctx._source.shirt.color = 'blue'"

Even better

{
 "query": ...
 "script": {
   "source": "ctx._source[params.field] = params.value;",
   "params": {
      "field": field,
      "value": value
      }
   }
 }

From here

1 Like

it's working, thanks :slight_smile:

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.