# What is this nesting in my mapping and what is its purpose?

**URL:** <https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565>\
**Category:** Elasticsearch\
**Created:** [April 25, 2018, 8:28pm UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565 "2018-04-25T20:28:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David9](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david9/32/42150_2.png) [@David9](https://discuss.elastic.co/u/David9)\
**Post date:** [April 25, 2018, 8:28pm UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565/1 "2018-04-25T20:28:33Z")

</div>

Looking at my mappings I'm often seeing something like this. I expect to see a flat country\_iso\_code having type text, but what is the keyword field? I don't see this in the raw data, I just see a country code value. Could it be that some of the data, which is machine-generated, has a nested structure? Thanks

> ```
> "country_iso_code": {
> "type": "text",
> "fields": {
> "keyword": {
> "type": "keyword",
> "ignore_above": 256
> }
> }
> },
> 
> ```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 26, 2018, 6:20am UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565/2 "2018-04-26T06:20:34Z")

</div>

It's automatically generated by elasticsearch because you did not define a mapping.  
It helps you in case you want to sort on `country_iso_code.keyword` or compute aggregations on it, which you can't do on `country_iso_code`.

---

<div class="post-metadata">

**Author:** ![David9](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david9/32/42150_2.png) [@David9](https://discuss.elastic.co/u/David9)\
**Post date:** [April 26, 2018, 11:35am UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565/3 "2018-04-26T11:35:38Z")

</div>

Thanks! So, does that mean there would be an explicit field called 'keyword' or country\_iso\_code.keyword? I don't see any evidence that my data source ever generated a field called country\_iso\_code.keyword. Also, I can't find what you're talking about in the documentation for mapping.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 26, 2018, 4:50pm UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565/4 "2018-04-26T16:50:25Z")

</div>

Elasticsearch never modifies the `_source` field which contains exactly what you sent.  
This field is generated 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 24, 2018, 4:50pm UTC](https://discuss.elastic.co/t/what-is-this-nesting-in-my-mapping-and-what-is-its-purpose/129565/5 "2018-05-24T16:50:31Z")

</div>

Closed on May 24, 2018, 4:50pm UTC

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