# Elasticsearch rename nested fields using reindex

**URL:** <https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956>\
**Category:** Elasticsearch\
**Created:** [August 17, 2018, 7:41pm UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956 "2018-08-17T19:41:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [August 17, 2018, 7:41pm UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956/1 "2018-08-17T19:41:07Z")

</div>

Trying to rename the existing fields using reindex api  
Works well for non-nested fields:

```
POST _reindex
{
  "source": {
    "index": "products-2018.04.05"
  },
  "dest": {
    "index": "products-reindex-2018.04.05"
  },
  "script": {
    "inline": "ctx._source.pid = ctx._source.remove(\"ProductID\")"
  }
}

```

But, when I tried on nested fields, its not working:

```
 POST _reindex
    {
      "source": {
        "index": "products-2018.04.05"
      },
      "dest": {
        "index": "products-reindex-2018.04.05"
      },
      "script": {
        "inline": "ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")"
      }
    }

```

Error:

```
{
    "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")",
          " ^---- HERE"
        ],
        "script": "ctx._source.PRODUCT.RPT.VALUEAVG = ctx._source.remove(\"PRODUCT.RPT.VALUE.AVG\")",
        "lang": "painless",
        "caused_by": {
          "type": "null_pointer_exception",
          "reason": null
        }
}

```

Mapping:

PRODUCT.RPT.VALUEAVG --\> text and not-analyzed

I tried different ways, nothing worked:

```
ctx._source.'PRODUCT.RPT.VALUEAVG'
ctx._source.\"PRODUCT.RPT.VALUEAVG"
ctx._source.[PRODUCT][RPT][VALUEAVG]
```

---

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [August 21, 2018, 1:11pm UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956/2 "2018-08-21T13:11:20Z")

</div>

Hi , anyone with solution to this problem.  
Any help appreciated !!

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 22, 2018, 7:51am UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956/3 "2018-08-22T07:51:54Z")

</div>

This syntax should work:

```auto
POST _reindex
{
  "source": {
    "index": "products-2018.04.05"
  },
  "dest": {
    "index": "products-reindex-2018.04.05"
  },
  "script": {
    "inline": """ctx._source['PRODUCT.RPT.VALUEAVG'] = ctx._source.remove("PRODUCT.RPT.VALUE.AVG")"""
  }
}

```

---

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [August 23, 2018, 10:55pm UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956/4 "2018-08-23T22:55:38Z")

</div>

Worked like a charm !! Thank you 😀

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 20, 2018, 10:55pm UTC](https://discuss.elastic.co/t/elasticsearch-rename-nested-fields-using-reindex/144956/5 "2018-09-20T22:55:38Z")

</div>

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