ElasticSearch - Copy one field value to other field for all documents

Viewed 8056

We have a field "name" in the index. We recently added a new field "alias". I want to copy name field value to the new field alias for all documents.

Is there any Update query that will do this? If that is not possible , Help me to achieve this. Thanks in advance

I am trying this query http://URL/index/profile/_update_by_query

{
  "query": {

        "constant_score" : {
            "filter" : {
                "exists" : { "field" : "name" }
            }
        }

  },
  "script" : "ctx._source.alias = name;"
}

In the script , I am not sure how to give name field. I getting error

{
  "error": {
    "root_cause": [
      {
        "type": "class_cast_exception",
        "reason": "java.lang.String cannot be cast to java.util.Map"
      }
    ],
    "type": "class_cast_exception",
    "reason": "java.lang.String cannot be cast to java.util.Map"
  },
  "status": 500
}
1 Answers
Related