# Renaming an existing field in a nested object

**URL:** <https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667>\
**Category:** Elasticsearch\
**Created:** [April 18, 2020, 5:45pm UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667 "2020-04-18T17:45:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waynesmallman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waynesmallman/32/18596_2.png) [@waynesmallman](https://discuss.elastic.co/u/waynesmallman)\
**Post date:** [April 18, 2020, 5:45pm UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/1 "2020-04-18T17:45:42Z")

</div>

Hi!

I need to rename an existing field in a nested object:

```
"shared": {
	"type": "nested",
	"properties": {
		"user_id": {
			"type": "long"
		},
		"creation": {
			"type": "date",
			"format": "date_hour_minute_second"
		},
		"access": {
			"type": "keyword"
		}
	}
}

```

… and so far I have the following request:

```
PUT _ingest/pipeline/rename_field_shared_access
{
 "description" : "Rename the 'shared.access' field to: 'shared.access_type'",
 "processors" : [
  {
   "rename": {
    "field": "shared.access",
    "target_field": "shared.access_type"
   }
  }
 ]
}

```

I'm assuming the dot notation is correct?

Also, I would need to extend the nested object with additional fields:

```
"shared": {
	"type": "nested",
	"properties": {
		"user_id": {
			"type": "long"
		},
		"creation": {
			"type": "date",
			"format": "date_hour_minute_second"
		},
		"modification": {
			"type": "date",
			"format": "date_hour_minute_second"
		},
		"access_type": {
			"type": "keyword"
		},
		"resource_recipient_type": {
			"type": "keyword"
		},
		"resource_recipient_id": {
			"type": "long"
		}
	}
}

```

I'm 99.9% this is possible using [Dynamic Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html), but I need to check with the experts!

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [April 18, 2020, 9:00pm UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/2 "2020-04-18T21:00:15Z")

</div>

I'm slightly confused — are we supposed to try it out for you or what is the specific question?

And yes, with dynamic mapping you can just add more fields to a document and they will be add with the default data types. But you could also extend the mapping manually if you prefer that.

---

<div class="post-metadata">

**Author:** ![waynesmallman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waynesmallman/32/18596_2.png) [@waynesmallman](https://discuss.elastic.co/u/waynesmallman)\
**Post date:** [April 18, 2020, 9:07pm UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/3 "2020-04-18T21:07:55Z")

</div>

I need to know if the PUT request is correct, given the sample from the mapping I'm using.

What would it involve to extend the mapping?

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [April 19, 2020, 2:45am UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/4 "2020-04-19T02:45:42Z")

</div>

> I need to know if the PUT request is correct, given the sample from the mapping I'm using.

Yes, but validate it for your own setup with:

```
PUT my-index/_doc/1?pipeline=rename_field_shared_access
{
  "shared": {
    "access": "foo"
  }
}

```

> What would it involve to extend the mapping?

The docs have a complete example of [updating a mapping after creating it](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#put-field-mapping-api-basic-ex) . Which should look like:

```
PUT /my-index/_mapping
{
  "properties": {
    "shared": {
      "type": "nested",
      "properties": {
        "user_id": {
          "type": "long"
        },
        "creation": {
          "type": "date",
          "format": "date_hour_minute_second"
        },
        "modification": {
          "type": "date",
          "format": "date_hour_minute_second"
        },
        "access_type": {
          "type": "keyword"
        },
        "resource_recipient_type": {
          "type": "keyword"
        },
        "resource_recipient_id": {
          "type": "long"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![waynesmallman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waynesmallman/32/18596_2.png) [@waynesmallman](https://discuss.elastic.co/u/waynesmallman)\
**Post date:** [April 19, 2020, 8:32am UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/5 "2020-04-19T08:32:17Z")

</div>

Excellent, but I have got two more questions:

1. Given that the instructions are in the Rename Processor, do I need to send an object payload in the PUT sample you've provided?
2. Is it possible to rename the field across an entire index? At a guess, remove the: "\_doc/:id".

As for the mapping, I do have mappings (4 of them for an existing application), so I would need to use Dynamic Mapping to add the additional fields.

Thanks the response — much appreciated.

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [April 23, 2020, 12:29am UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/6 "2020-04-23T00:29:41Z")

</div>

> - Given that the instructions are in the Rename Processor, do I need to send an object payload in the PUT sample you've provided?

No, there are multiple ways. An index could have a default ingest pipeline that is being applied. Or if data is being sent from a Beat you could specify that there. But you need need to define in one way or another which pipeline (if any) to use.

> - Is it possible to rename the field across an entire index? At a guess, remove the: "\_doc/:id".

No, that would require an `_update_by_query` or a full `_reindex` (both support ingest processors and scripts), but those are heavy operations since every change is a delete+ index operation in Lucene.

---

<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:** [May 21, 2020, 12:29am UTC](https://discuss.elastic.co/t/renaming-an-existing-field-in-a-nested-object/228667/7 "2020-05-21T00:29:43Z")

</div>

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