# \_bucket\_count in bucket\_selector- pipeline aggregation

**URL:** https://discuss.elastic.co/t/-bucket-count-in-bucket-selector-pipeline-aggregation/85519
**Category:** Elasticsearch
**Created:** [May 12, 2017, 8:13am UTC](https://discuss.elastic.co/t/-bucket-count-in-bucket-selector-pipeline-aggregation/85519 "2017-05-12T08:13:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)
#### Post date: [May 12, 2017, 8:13am UTC](https://discuss.elastic.co/t/-bucket-count-in-bucket-selector-pipeline-aggregation/85519/1 "2017-05-12T08:13:39Z")

</div>

hello,  
I'm trying to make this work with no luck. should this syntax even work?  
I am referring this git issue:

> <https://github.com/elastic/elasticsearch/pull/19571>

thanks!

```
GET client_data_228_d_2017-03-15,client_data_228_d_2017-03-16/prt/_search?ignore_unavailable
{
  "size": 0,
  "aggs": {
    "groupby_country": {
      "terms": {
        "field": "country",
        "size": 2000
      },
      "aggs": {
        "should_we_consider": {
          "bucket_selector": {
            "buckets_path": {
              "hits": "groupby_domain. **_bucket_count**"
            },
            "script": "_bucket_count.hits>0"
          }
        },
        "groupby_domain": {
          "terms": {
            "field": "domain",
            "size": 2000
          },
          "aggs": {
            "groupby_page": {
              "terms": {
                "field": "page",
                "size": 2000,
                "min_doc_count": 2
              }
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)
#### Post date: [May 12, 2017, 11:07am UTC](https://discuss.elastic.co/t/-bucket-count-in-bucket-selector-pipeline-aggregation/85519/2 "2017-05-12T11:07:01Z")

</div>

was a silly copy-paste error.

```
{
  "size": 0,
  "aggs": {
    "groupby_country": {
      "terms": {
        "field": "country",
        "size": 2000
      },
      "aggs": {
        "should_we_consider": {
          "bucket_selector": {
            "buckets_path": {
              "hits": "groupby_domain._bucket_count"
            },
            "script": "params.hits > 0"
          }
        },
        "groupby_domain": {
          "terms": {
            "field": "domain",
            "size": 2000
          },
          "aggs": {
            "groupby_page": {
              "terms": {
                "field": "page",
                "size": 2000,
                "min_doc_count": 2
              }
            }
          }
        }
      }
    }
  }
}
```

---

<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 9, 2017, 11:07am UTC](https://discuss.elastic.co/t/-bucket-count-in-bucket-selector-pipeline-aggregation/85519/3 "2017-06-09T11:07:04Z")

</div>

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