# Mapping all nested fields

**URL:** <https://discuss.elastic.co/t/mapping-all-nested-fields/79816>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 9:33pm UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816 "2017-03-23T21:33:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmyokoyama](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kmyokoyama](https://discuss.elastic.co/u/kmyokoyama)\
**Post date:** [March 23, 2017, 9:33pm UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816/1 "2017-03-23T21:33:41Z")

</div>

Hello, everyone.

I'm trying to index an object like this (shown partially):

```auto
...
"stats": {
    "stats_0": "0",
    "stats_0": "0",
    ...
    "stats_99": "99"
}
...

```

But I'm not being successful: It's indexed as string and I need it to be of numeric type. I think there's two approaches to this problem: 1) provide mappings to those fields or 2) convert those nested fields into long in the pipeline. The problem is I don't know how to do this in a compact way. I don't want to write

```auto
...
"stats": {
    "properties": {
        "stats0": {
            "type": "long"
        }
       "stats1": {
            "type": "long"
        }
        ...
       "stats99": {
            "type": "long"
        }
    }
}
...

```

There must be a way to do this for all nested fields at once.

Sorry if it was unclear.

Thank you.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 24, 2017, 6:06am UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816/2 "2017-03-24T06:06:20Z")

</div>

This is more of an Elasticsearch question so you'll probably have more luck moving your post to that category.

---

<div class="post-metadata">

**Author:** ![kmyokoyama](https://avatars.discourse-cdn.com/v4/letter/k/71e660/32.png) [@kmyokoyama](https://discuss.elastic.co/u/kmyokoyama)\
**Post date:** [March 27, 2017, 2:16pm UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816/3 "2017-03-27T14:16:50Z")

</div>

Moved. Thanks.

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [March 28, 2017, 9:00am UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816/4 "2017-03-28T09:00:06Z")

</div>

You have some options.

1. Use [Numeric detection](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html#numeric-detection)  
you can control which level is enabled/disabled.
2. Use [dynamic templates](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/dynamic-templates.html)  
If there are some rules for field name, e.x. `stats_*`, you can define custom mappings by dynamic templates

---

<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:** [April 25, 2017, 9:00am UTC](https://discuss.elastic.co/t/mapping-all-nested-fields/79816/5 "2017-04-25T09:00:34Z")

</div>

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