# Setting a default value for missing fields during indexing

**URL:** <https://discuss.elastic.co/t/setting-a-default-value-for-missing-fields-during-indexing/45021>\
**Category:** Elasticsearch\
**Created:** [March 21, 2016, 4:32pm UTC](https://discuss.elastic.co/t/setting-a-default-value-for-missing-fields-during-indexing/45021 "2016-03-21T16:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michele\_crudele](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@michele\_crudele](https://discuss.elastic.co/u/michele_crudele)\
**Post date:** [March 21, 2016, 4:32pm UTC](https://discuss.elastic.co/t/setting-a-default-value-for-missing-fields-during-indexing/45021/1 "2016-03-21T16:32:37Z")

</div>

I would like to set in my mappings file a default value for all fields of a given type that are missing in the doc while indexing. I mean something like:

```auto
{
    "mappings": {
        "defaults_by_type": {
            "string": "NA",
           "long": NaN,
          "double": NaN,
          "date": "1970-01-01"
        },
        "my_type": {
         "properties": {...}
        }
    }
}

```

that means literally: when any of the string fields in the source doc does not have a value, then use the string "NA", and similarly for the other types.  
Is that actually available? If not, how can I achieve the same results?  
Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 22, 2016, 7:40am UTC](https://discuss.elastic.co/t/setting-a-default-value-for-missing-fields-during-indexing/45021/2 "2016-03-22T07:40:07Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html) should do what you want.

---

<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 5, 2017, 11:06pm UTC](https://discuss.elastic.co/t/setting-a-default-value-for-missing-fields-during-indexing/45021/3 "2017-07-05T23:06:23Z")

</div>


