# Definition of index-templates for whole sub-structures needed?

**URL:** https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647
**Category:** Elasticsearch
**Created:** [December 7, 2017, 10:43am UTC](https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647 "2017-12-07T10:43:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ppuschmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppuschmann/32/146751_2.png) [@ppuschmann](https://discuss.elastic.co/u/ppuschmann)
#### Post date: [December 7, 2017, 10:43am UTC](https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647/1 "2017-12-07T10:43:42Z")

</div>

Hi,  
we're currently having an interesting issue with our field-definitions and type-detection.

We have fields in our documents that sometimes contain integers, sometimes some strings.

In the documentation we find some parts regarding object datatypes: [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/object.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/object.html)

Given we have this template defined:

```
PUT my_index
{
  "mappings": {
    "my_type": { 
      "properties": {
        "region": {
          "type": "keyword"
        },
        "manager": { 
          "properties": {
            "age": { "type": "integer" },
            "name": { 
              "properties": {
                "first": { "type": "text" },
                "last": { "type": "text" },
                "somefield": { "type": "keyword" }
              }
            }
          }
        }
      }
    }
  }
}

```

The field `somefield` is in this case our field with mixed input types.

Would this index-template be valid for documents, that don't have a field `somefield` (or `name.somefield`)?

So, is the example-template valid for all four example-documents?

Example 1:

```
PUT my_index/my_type/1
{ 
  "region": "US",
  "manager": { 
    "age": 30,
    "name": { 
      "first": "John",
      "last": "Doe"
    }
  }
}

```

Example 2:

```
PUT my_index/my_type/2
{ 
  "region": "US",
  "manager": { 
    "age": 35,
    "name": { 
      "first": "Patty",
      "last": "Myers",
      "somefield": "Some text..."
    }
  }
}

```

Example 3:

```
PUT my_index/my_type/3
{ 
  "region": "US",
  "manager": { 
    "age": 35,
    "name": { 
      "first": "Patrick",
      "last": "McDonald",
      "somefield": 42
    }
  }
}

```

Example 4:

```
PUT my_index/my_type/4
{ 
  "region": "US",
  "manager": { 
    "age": 35,
    "name": { 
      "first": "Patrick",
      "last": "McDonald",
      "somefield": 42,
      "somedifferentfield": 42
    }
  }
}
```

---

<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: [December 8, 2017, 9:14am UTC](https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647/2 "2017-12-08T09:14:14Z")

</div>

Yes, fields are optional in Elasticsearch, so an index with your mapping will happily accept those documents. Any unmapped field that shows up in a document (like your `somedifferentfield`) will be [dynamically mapped](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html), in your case to a `long` type.

---

<div class="post-metadata">

### Author: ![ppuschmann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppuschmann/32/146751_2.png) [@ppuschmann](https://discuss.elastic.co/u/ppuschmann)
#### Post date: [December 12, 2017, 5:31pm UTC](https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647/3 "2017-12-12T17:31:25Z")

</div>

Thanks for the clarification.

---

<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: [January 9, 2018, 5:31pm UTC](https://discuss.elastic.co/t/definition-of-index-templates-for-whole-sub-structures-needed/110647/4 "2018-01-09T17:31:26Z")

</div>

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