# Aggregations: always include item (even if zero results)

**URL:** <https://discuss.elastic.co/t/aggregations-always-include-item-even-if-zero-results/87483>\
**Category:** Elasticsearch\
**Created:** [May 29, 2017, 6:36pm UTC](https://discuss.elastic.co/t/aggregations-always-include-item-even-if-zero-results/87483 "2017-05-29T18:36:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LEDfan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ledfan/32/18599_2.png) [@LEDfan](https://discuss.elastic.co/u/LEDfan)\
**Post date:** [May 29, 2017, 6:36pm UTC](https://discuss.elastic.co/t/aggregations-always-include-item-even-if-zero-results/87483/1 "2017-05-29T18:36:11Z")

</div>

Hi

I'm building a Faceted search using ElasticSearch and python ([http://elasticsearch-dsl.readthedocs.io/en/latest/](http://elasticsearch-dsl.readthedocs.io/en/latest/)). I'm using aggregations for this. Everything is working fine, except one issue: if the user selects an option, this option must stay selected, even if it's filtered out because there are options with a higher count.

I didn't found a way to do this, so I added an extra aggregation which only fetches the selected option:

```auto
POST question/question/_search
{
   "aggs": {
      "_selected_filter_status": {
         "aggs": {
            "status": {
               "terms": {
                  "field": "status.keyword",
                  "min_doc_count": 0,
                  "include": [
                     "9",
                     "11"
                  ]
               }
            }
         },
         "filter": {
            "terms": {
               "nonprofit.name.keyword": [
                  "xxxxx"
               ]
            }
         }
      }
   },
   "query": {
      "match_all": {}
   }
}

```

The result is:

```auto
 "aggregations": {
      "_selected_filter_status": {
         "doc_count": 1,
         "status": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
               {
                  "key": "9",
                  "doc_count": 1
               }
            ]
         }
      }
   }

```

So as you see there is no bucket for status "11". Any idea why elastic does this, or how I can solve this?

Thanks in advance

---

<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:** [June 26, 2017, 6:36pm UTC](https://discuss.elastic.co/t/aggregations-always-include-item-even-if-zero-results/87483/2 "2017-06-26T18:36:16Z")

</div>

Closed on June 26, 2017, 6:36pm UTC

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