elasticsearchelastic-stackelasticsearch-nested

Error when trying to rename a nested object name in elasticsearch


I'm trying to rename data that is in this shape:

enter image description here

using this:

POST r_xair_signals-2020-06/_update/2020-06-15T22:23:00Z_-1344027716
{
  "doc" : {
        "Customer ImpactedNested" : "CustomerImpactedNested"
    }
}

But I'm getting:

"type": "mapper_parsing_exception",
    "reason": "object mapping for [Customer ImpactedNested] tried to parse field [Customer ImpactedNested] as object, but found a concrete value"

I've confirmed the type of Customer ImpactedNested is nested. I see info online about people getting this error, but not when trying to rename, and don't see any solutions. I saw one article that indicated it occurred when the new name conflicted with an existing name. So, tried renaming to CustomerImpactedNested11111 as a test (sure to be unique), but same result.

Any ideas would be great!


Solution

  • There are two problems actually.

    1. Your query is not renaming the field.
    2. Renaming the nested field

    What is happening actually in the following line from the question:

    POST r_xair_signals-2020-06/_update/2020-06-15T22:23:00Z_-1344027716
    {
      "doc" : {
            "Customer ImpactedNested" : "CustomerImpactedNested"
        }
    }
    

    It updates column value of column=Customer ImpactedNested to CustomerImpactedNested document whose id is 2020-06-15T22:23:00Z_-1344027716.

    And Customer ImpactedNested is a nested object and you are trying to set a string value to the nested object field. Hence you are getting the error. Refer this

    Coming to your original problem, you need to do this via reindex. Refer this, this also

    POST _reindex
    {
      "source": {
        "index": "r_xair_signals-2020-06"
      },
      "dest": {
        "index": "<some_new_index_name>"
      },
      "script": {
        "inline": """ctx._source['CustomerImpactedNested'] = ctx._source.remove("Customer ImpactedNested")"""
      }
    }
    

    Please try the above and let me know for errors as I didn't try the above query.