update_by_query for multi field

374 views Asked by At

I have added a new multi field (raw) of an existing field (response) in the index. And since the new multi field raw will have no data. I tried to add data from source as below.

POST /y_metrics/response/_update_by_query
{
  "script":{
    "inline":  "ctx._source.response['raw'] = ctx._source.response;"
  },
  "query": {
        "match_all": {}
    }
}

fails :

 "type": "missing_property_exception",
 "reason": "No such property: raw for class: java.lang.String"

2nd try :

POST /y_metrics/response/_update_by_query
{
  "script":{
    "inline":  "ctx._source['response.raw'] = ctx._source.response;"
  },
  "query": {
        "match_all": {}
    }
}

fails:

    "type": "mapper_parsing_exception",
    "reason": "Field name [response.raw] cannot contain '.'"

Apparently, the problem seems to be because of ".". But how else one would access multi field in this case ? I read about de_dot filter does it help in my case ?

1

There are 1 answers

3
alr On BEST ANSWER

if you add a field to an existing field (thus a multi field), there is no need to use a script, just reindex and Elasticsearch will handle the rest. You can just drop the script part of your update by query call.