# Nested datatype and dynamic mapping

**URL:** <https://discuss.elastic.co/t/nested-datatype-and-dynamic-mapping/82338>\
**Category:** Elasticsearch\
**Created:** [April 13, 2017, 6:22pm UTC](https://discuss.elastic.co/t/nested-datatype-and-dynamic-mapping/82338 "2017-04-13T18:22:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maziyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maziyar/32/18423_2.png) [@maziyar](https://discuss.elastic.co/u/maziyar)\
**Post date:** [April 13, 2017, 6:22pm UTC](https://discuss.elastic.co/t/nested-datatype-and-dynamic-mapping/82338/1 "2017-04-13T18:22:07Z")

</div>

Hi,

I have a nested object which is mapped as follow:

```
         "product": {
            "type": "nested",
            "properties": {
              "id": {
                "type": "long"
              }
              "level": {
                "type": "long"
              }
              "name": {
                "type": "text"
              }
            }

```

I also have a dynamic template as follow to add "raw" as a keyword type to text data type:

```
"dynamic_templates": [
      {
        "strings_as_keywords": {
          "match_mapping_type": "string",
          "mapping": {
            "fields": {
              "raw": {
                "ignore_above": 1024,
                "type": "keyword"
              }
            },
            "norms": false,
            "type": "text"
          }
        }
      }
 ...

```

Now my problem is, everything in this nested object works as expected except the nested aggregation over only **text** field (not the long data type). And that is because Fielddata is disabled on text fields and when I look at the \_mapping of my created index I don't see the "raw" field as well.

So my question is, why the dynamic template works for all the others but not for this nested object? And what would you suggest to have both text/keyword in nested data type.

Thanks,  
Maziyar

---

<div class="post-metadata">

**Author:** ![maziyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maziyar/32/18423_2.png) [@maziyar](https://discuss.elastic.co/u/maziyar)\
**Post date:** [April 26, 2017, 10:27am UTC](https://discuss.elastic.co/t/nested-datatype-and-dynamic-mapping/82338/2 "2017-04-26T10:27:10Z")

</div>

Ok I had to fix the mapping as the following and re-index each index by using Reindex API, dynamic mapping didn't work on the nested objects:

```
      "product": {
        "type": "nested",
        "properties": {
          "name": {
            "type": "text",
           "fields": {
              "raw": {
                "type": "keyword"
              }
            }
          }

```

Best,  
Maziyar

---

<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, 2017, 10:34am UTC](https://discuss.elastic.co/t/nested-datatype-and-dynamic-mapping/82338/3 "2017-05-24T10:34:45Z")

</div>

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