# How to count empty fields zero

**URL:** <https://discuss.elastic.co/t/how-to-count-empty-fields-zero/364945>\
**Category:** Logstash\
**Created:** [August 15, 2024, 9:51am UTC](https://discuss.elastic.co/t/how-to-count-empty-fields-zero/364945 "2024-08-15T09:51:36Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Musab\_Dogan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/musab_dogan/32/70691_2.png) [@Musab\_Dogan](https://discuss.elastic.co/u/Musab_Dogan)\
**Post date:** [August 15, 2024, 11:08am UTC](https://discuss.elastic.co/t/how-to-count-empty-fields-zero/364945/3 "2024-08-15T11:08:06Z")

</div>

Selam Umut,  
You can use an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) and add that ingest pipeline into index settings. In that way, the fields with `null` value will have `0` value.

Here is an example for you:

```auto
PUT _ingest/pipeline/convert_empty_to_zero
{
  "processors": [
    {
      "script": {
        "source": """
          for (entry in ctx.entrySet()) {
            if (entry.getValue() == '') {
              ctx[entry.getKey()] = 0;
            }
          }
        """
      }
    }
  ]
}

PUT coronavirus-1/_settings
{
  "index.default_pipeline": "convert_empty_to_zero"
}

PUT coronavirus-1/_doc/1
{
  "country": "Turkiye",
  "cumulative": 100,
  "daily_new": 10,
  "active_cases": ""
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/3/534014547776e6af7199291009ada78fc60b4672.jpeg)

Note: I recommend to use the ingest pipeline but if you wish you can also do that on Logstash side. Check [this](https://discuss.elastic.co/t/how-to-write-null-value-for-a-field/53885) discussion for how.  
Note2: You can also update your index mapping with [null\_value | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html) but it looks like it's not fit for your use case.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-count-empty-fields-zero/364945)._
