# DSL query aggregation question

**URL:** <https://discuss.elastic.co/t/dsl-query-aggregation-question/242873>\
**Category:** Elasticsearch\
**Created:** [July 28, 2020, 9:43am UTC](https://discuss.elastic.co/t/dsl-query-aggregation-question/242873 "2020-07-28T09:43:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.silwon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/d.silwon/32/65853_2.png) [@d.silwon](https://discuss.elastic.co/u/d.silwon)\
**Post date:** [July 28, 2020, 9:43am UTC](https://discuss.elastic.co/t/dsl-query-aggregation-question/242873/1 "2020-07-28T09:43:10Z")

</div>

Dears,

I have some query with aggregation like this:

```auto
  "aggs": {
    "NAME": {
      "terms": {
        "script": "doc['si.rc.keyword'].getValue().substring(0,1)",
        "order": {
          "_key": "asc"
        }
        }
      }
    }

```

the result looks like:

```auto
{
  "key" : "0",
  "doc_count":"5436"
},
{
  "key" : "1",
  "doc_count":"7898"
},
{
  "key" : "2",
  "doc_count":"3233"
}

```

Is there any way to do write such aggregation so that when some case doesn't exist the result will show 0, for example:

```auto
{
  "key" : "0",
  "doc_count":"5436"
},
{
  "key" : "1",
  "doc_count":"0"
},
{
  "key" : "2",
  "doc_count":"3233"
}

```

The si.rc is a text.

Best Regards,  
Dan

---

<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:** [August 25, 2020, 9:43am UTC](https://discuss.elastic.co/t/dsl-query-aggregation-question/242873/2 "2020-08-25T09:43:17Z")

</div>

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