# Adding default values to the doc is not working

**URL:** https://forum.opensearch.org/t/adding-default-values-to-the-doc-is-not-working/21318
**Category:** OpenSearch
**Tags:** configure
**Created:** [September 11, 2024, 2:03pm UTC](https://forum.opensearch.org/t/adding-default-values-to-the-doc-is-not-working/21318 "2024-09-11T14:03:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rajanimaski](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@rajanimaski](https://forum.opensearch.org/u/rajanimaski)
#### Post date: [September 11, 2024, 2:03pm UTC](https://forum.opensearch.org/t/adding-default-values-to-the-doc-is-not-working/21318/1 "2024-09-11T14:03:19Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
Latest

**Describe the issue** :  
The null\_value is configured however the field is not populated when the document is sent without the field.

**Configuration** :

```auto
PUT my-index-01/
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "is_active": {
        "type": "boolean",
        "null_value": "false"
      }
    }
  }
}

POST my-index-01/_doc/2
{
  "keywords" : "test"
}

GET my-index-01/_search
{
  "query": {
    "match": {
      "is_active": "false"
    }
  }
}

```

 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/35631f158ca7b25a617cab41d63dc37a0e950d60.png)

---

<div class="post-metadata">

### Author: ![rajanimaski](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@rajanimaski](https://forum.opensearch.org/u/rajanimaski)
#### Post date: [September 11, 2024, 7:42pm UTC](https://forum.opensearch.org/t/adding-default-values-to-the-doc-is-not-working/21318/2 "2024-09-11T19:42:19Z")

</div>

Figured that setting null\_value is not same as setting default value.

Related -

> **[Field null\_value doesn't seem to have any effect?](https://discuss.elastic.co/t/field-null-value-doesnt-seem-to-have-any-effect/22015)**
>
> Hello, I've configured the null\_value of a field, as below. But when I do a query, the documents that lack a barfield, don't return the value "0" for the 'barfield' as expected. What could be the reason? "foo": { "properties": { ...

> <https://stackoverflow.com/questions/58196842/setting-a-default-value-for-missing-fields-during-indexing>

---

<div class="post-metadata">

### Author: ![rajanimaski](https://avatars.discourse-cdn.com/v4/letter/r/87869e/32.png) [@rajanimaski](https://forum.opensearch.org/u/rajanimaski)
#### Post date: [September 12, 2024, 1:15pm UTC](https://forum.opensearch.org/t/adding-default-values-to-the-doc-is-not-working/21318/3 "2024-09-12T13:15:52Z")

</div>

Alternative is set the value to null in the indexing service. The following works alright -

```auto
PUT my-index-01/
{
  "mappings": {
    "dynamic": false,
    "properties": {
      "is_active": {
        "type": "boolean",
        "null_value": "false"
      }
    }
  }
}

POST my-index-01/_doc/2
{
  "keywords" : "test",
  "is_active" : null
}

GET my-index-01/_search
{
  "query": {
    "match": {
      "is_active": "false"
    }
  }
}

```
