Need help using a bucket_script with single-value or filters filters

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.

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

 "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
                }
              }
            }
          },

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