# Need help using a bucket\_script with single-value or filters filters

**URL:** <https://discuss.elastic.co/t/need-help-using-a-bucket-script-with-single-value-or-filters-filters/241544>\
**Category:** Elasticsearch\
**Created:** [July 16, 2020, 8:56pm UTC](https://discuss.elastic.co/t/need-help-using-a-bucket-script-with-single-value-or-filters-filters/241544 "2020-07-16T20:56:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![teebu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teebu/32/10119_2.png) [@teebu](https://discuss.elastic.co/u/teebu)\
**Post date:** [July 16, 2020, 8:56pm UTC](https://discuss.elastic.co/t/need-help-using-a-bucket-script-with-single-value-or-filters-filters/241544/1 "2020-07-16T20:56:41Z")

</div>

I'm trying to compute count of a nested field where active and inactive is not 0 for both values. But I can't get my aggs working inside the bucket\_script. Initially I tried using the `active_entities" : { "filter"` but I i think it requires multi-bucket to work, so I switched it to `filters filters`. Ideally I'd like to use the original filter.

```auto
GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {"term": {"document_id.keyword": "1"}} 
      ]
    }
  },
  "size": 0, 
  "aggs": {
    "entities" : {
      "nested" : {"path" : "entities"},
      "aggs" : {
        "detected_entity_types" : { 
          "terms": { "field" : "entities.text.keyword" },
          
          "aggs" : {
            "entity_type" : { "terms": { "field": "entities.type.keyword" } },
            
            "redaction_status" : {
              "filters": {
                  "filters": {
                    "active" : { "match" : { "entities.redacted" : "true" }},
                    "inactive" : { "match" : { "entities.redacted" : "false" }}
                  }
                }
              }
              
              ,"count_not_eq": {
                "bucket_script": {
                  "buckets_path": { "active": "redaction_status.active", "inactive": "redaction_status.inactive" },
                  "script": { "source": "logic here" }
              }}
              
            // single bucket not working with bucket_script, needs multi-bucket filters filters?
            //,"active_entities" : { "filter" : { "bool": {"must": [{"term": { "entities.redacted": true}}] }} }
            //,"inactive_entities" : { "filter" : { "bool": {"must": [{"term": { "entities.redacted": false}}] }} }
            
          }
                    
        }
      }
    }
  }
}

```

Snippet of result

```auto
 "aggregations" : {
    "entities" : {
      "doc_count" : 214,
      "detected_entity_types" : {
        "doc_count_error_upper_bound" : 0,
        "sum_other_doc_count" : 160,
        "buckets" : [
          {
            "key" : "2017",
            "doc_count" : 8,
            "entity_type" : {
              "doc_count_error_upper_bound" : 0,
              "sum_other_doc_count" : 0,
              "buckets" : [
                {
                  "key" : "DATE",
                  "doc_count" : 8
                }
              ]
            },
            "redaction_status" : {
              "buckets" : {
                "active" : {
                  "doc_count" : 0
                },
                "inactive" : {
                  "doc_count" : 8
                }
              }
            }
          },

```

---

<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 13, 2020, 8:56pm UTC](https://discuss.elastic.co/t/need-help-using-a-bucket-script-with-single-value-or-filters-filters/241544/2 "2020-08-13T20:56:45Z")

</div>

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