# How can we make field optional in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419>\
**Category:** Elasticsearch\
**Created:** [June 24, 2020, 9:20am UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419 "2020-06-24T09:20:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdul\_Gaffar\_Shaikh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_gaffar_shaikh/32/78006_2.png) [@Abdul\_Gaffar\_Shaikh](https://discuss.elastic.co/u/Abdul_Gaffar_Shaikh)\
**Post date:** [June 24, 2020, 9:20am UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419/1 "2020-06-24T09:20:04Z")

</div>

i am trying to ingested csv file into elasticsearch via logstash and i have a dedicated schema for it. my data gets ingested for date fields where format is not specified and with format specified , it throws that into DLQ. Could i make these field optional(3 fields are populated based on condition and not simultaneously) if blank and get the rest the fields ingested in document and only throw it in dlq if the format is invalid?

---

<div class="post-metadata">

**Author:** ![abrx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abrx/32/43881_2.png) [@abrx](https://discuss.elastic.co/u/abrx)\
**Post date:** [June 24, 2020, 9:47am UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419/2 "2020-06-24T09:47:19Z")

</div>

Elasticsearch is a NoSQL database, meaning that you can index data dynamically. You can index several documents in the same index that have different structure while there's no type conflicts between them.  
You should avoid to have sparse data for performance and agregation purpose but you can have some field added or missing.  
The mapping allow to cast type to fileds but doesn't make them mandatory.

---

<div class="post-metadata">

**Author:** ![Abdul\_Gaffar\_Shaikh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdul_gaffar_shaikh/32/78006_2.png) [@Abdul\_Gaffar\_Shaikh](https://discuss.elastic.co/u/Abdul_Gaffar_Shaikh)\
**Post date:** [June 24, 2020, 10:08am UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419/3 "2020-06-24T10:08:25Z")

</div>

while for any other type its fine , but for date field it doesn't seem so.

---

<div class="post-metadata">

**Author:** ![abrx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abrx/32/43881_2.png) [@abrx](https://discuss.elastic.co/u/abrx)\
**Post date:** [June 24, 2020, 1:41pm UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419/4 "2020-06-24T13:41:16Z")

</div>

Yes, but logstash can put the indexation date by default

---

<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:** [July 22, 2020, 1:41pm UTC](https://discuss.elastic.co/t/how-can-we-make-field-optional-in-elasticsearch/238419/5 "2020-07-22T13:41:18Z")

</div>

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