# How to use the Bucket Selector to emulate min\_doc\_count?

**URL:** <https://discuss.elastic.co/t/how-to-use-the-bucket-selector-to-emulate-min-doc-count/37049>\
**Category:** Elasticsearch\
**Created:** [December 13, 2015, 2:48am UTC](https://discuss.elastic.co/t/how-to-use-the-bucket-selector-to-emulate-min-doc-count/37049 "2015-12-13T02:48:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreKR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrekr/32/6233_2.png) [@AndreKR](https://discuss.elastic.co/u/AndreKR)\
**Post date:** [December 13, 2015, 2:48am UTC](https://discuss.elastic.co/t/how-to-use-the-bucket-selector-to-emulate-min-doc-count/37049/1 "2015-12-13T02:48:42Z")

</div>

I want to eliminate all empty buckets from a range aggregation.

According to [https://github.com/elastic/elasticsearch/issues/10027](https://github.com/elastic/elasticsearch/issues/10027) the [Bucket Selector Pipeline Aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-aggregations-pipeline-bucket-selector-aggregation.html#issuecomment-162449165) is the way to go, but I'm struggling with its syntax. Here's what I have so far:

```auto
{
  "aggs": {
    "values_histogram": {
      "range": {
        "field": "value",
        "ranges": [
          { "from": 1, "to": 2 },
          { "from": 2, "to": 3 },
          { "from": 3, "to": 4 }
        ]
      },
      "aggs": {
        "the_filter": {
          "bucket_selector": {
            "buckets_path": {
              "the_doc_count": "values_histogram.doc_count"
            },
            "script": "the_doc_count > 0"
          }
        }
      }
    }
  }
}

```

But this gives me the error:

```
No aggregation found for path [values_histogram.doc_count]
```

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [December 14, 2015, 9:56am UTC](https://discuss.elastic.co/t/how-to-use-the-bucket-selector-to-emulate-min-doc-count/37049/2 "2015-12-14T09:56:16Z")

</div>

If you change your `buckets_path` to the following it should work:

```auto
"buckets_path": {
    "the_doc_count": "_count"
},

```

The `buckets_path` is relative to the parent aggregation (in this case `values_histogram`) and `_count` and `_key` are both special keywords to indicate the document count of the bucket and the key of the bucket respectively.

Hope that helps

---

<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:31pm UTC](https://discuss.elastic.co/t/how-to-use-the-bucket-selector-to-emulate-min-doc-count/37049/3 "2017-07-05T23:31:21Z")

</div>


