Will All Template Fields be Present on an Index?

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

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.

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)

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:

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.

1 Like

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