# Optional fields in custom index template

**URL:** <https://discuss.elastic.co/t/optional-fields-in-custom-index-template/229869>\
**Category:** Elasticsearch\
**Created:** [April 26, 2020, 8:45pm UTC](https://discuss.elastic.co/t/optional-fields-in-custom-index-template/229869 "2020-04-26T20:45:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [April 26, 2020, 8:45pm UTC](https://discuss.elastic.co/t/optional-fields-in-custom-index-template/229869/1 "2020-04-26T20:45:36Z")

</div>

Hi, Im consuming events from logstash to elastic, I have created an index template for it, Every document will have ONE of this three fields, so if a document has "uptime\_seconds" the other fields will be empty, So I was wandering if I there is a way to specify in the template that those fields wil be optional?

```auto
      "uptime_seconds": {
        "type": "long"
      }
      "memory_pct": {
        "type": "long"
      }
      "cpu_pct": {
        "type": "long"
      }

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 27, 2020, 2:10am UTC](https://discuss.elastic.co/t/optional-fields-in-custom-index-template/229869/2 "2020-04-27T02:10:55Z")

</div>

You do not need to. The mapping specified how to index fields, not whether they need to be present or not.

---

<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 25, 2020, 2:21am UTC](https://discuss.elastic.co/t/optional-fields-in-custom-index-template/229869/4 "2020-05-25T02:21:21Z")

</div>

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