# Will All Template Fields be Present on an Index?

**URL:** <https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763>\
**Category:** Elasticsearch\
**Created:** [August 2, 2018, 12:27pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763 "2018-08-02T12:27:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanrossiter](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@ryanrossiter](https://discuss.elastic.co/u/ryanrossiter)\
**Post date:** [August 2, 2018, 12:27pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763/1 "2018-08-02T12:27:01Z")

</div>

Hi, I am wondering if when an index template has fields defined that aren't present on the data being inserted into an index (none of the data has the field present), will those fields still exist on the index? Or will they only be created when the data contains the field?

Thanks

---

<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:** [August 2, 2018, 12:39pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763/2 "2018-08-02T12:39:31Z")

</div>

The index template is applied at creation time of the index, whatever data will be inserted later.  
If you are speaking about dynamic templates, that's then another question. Indeed the fields are created only when one document is adding a field that matches the dynamic template.

Note that a dynamic template can be defined in an index template.

---

<div class="post-metadata">

**Author:** ![ryanrossiter](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@ryanrossiter](https://discuss.elastic.co/u/ryanrossiter)\
**Post date:** [August 2, 2018, 1:06pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763/3 "2018-08-02T13:06:36Z")

</div>

Thanks David

Just to verify, if I create a template like this:

> ```
> PUT _template/test {
> "index_patterns": ["my_index-*"],
> "mappings": {
> "doc": {
> "properties": {
> "Time_Stamp_A": {
> "type": "date",
> "format": "epoch_second"
> },
> "Time_Stamp_B": {
> "type": "date",
> "format": "epoch_second"
> }
> }
> }
> }
> }
> 
> ```

And then I only insert data that has Time\_Stamp\_A into my\_index-A, that index won't contain Time\_Stamp\_B? (Until I insert data that has a Time\_Stamp\_B field)

---

<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:** [August 3, 2018, 6:18pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763/4 "2018-08-03T18:18:51Z")

</div>

With this command you are defining an index mapping.

When you are going to create a new index named `my_index-foo`, Elasticsearch will basically do for you this:

```auto
PUT my_index-foo
{
    "mappings": {
        "doc": {
            "properties": {
                "Time_Stamp_A": {
                    "type": "date",
                    "format": "epoch_second"
                },
                "Time_Stamp_B": {
                    "type": "date",
                    "format": "epoch_second"
                }
            }
        }
}

```

So `Time_Stamp_B` will be defined in the mapping.

Then you will send data. As you can see, index template does not care about the data you are going to send after.

---

<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:** [August 31, 2018, 6:18pm UTC](https://discuss.elastic.co/t/will-all-template-fields-be-present-on-an-index/142763/5 "2018-08-31T18:18:59Z")

</div>

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