Filters Aggregation Bucket Selector

I am trying to find term values that exist in two separate geo_bounding_box queries. So far I have a term aggregate to which I apply a filters aggregate that contains the two geo_bounding_box queries. However, some of the buckets contain geo_bounding_box "inner" buckets with doc_counts of zero. I was wondering if it's possible to use a bucket selector to select buckets with inner buckets that have a doc_count > 0. I have only been able to select buckets with a total count > 0. I am using version 5.4 of Elasticsearch.

Query:

POST index/_search
     {
      "size": 0,
      "query": {
        "bool": {
          "should" : [
            {
              "geo_bounding_box": {
                "geo_point": {
                  "top_left": {
                    "lat": 0,
                    "lon": -45
                  },
                  "bottom_right": {
                    "lat": -25,
                    "lon": -30
                  }
                }
              }
            },
            {
              "geo_bounding_box": {
                "geo_point": {
                  "top_left": {
                    "lat": 50,
                    "lon": -125
                  },
                  "bottom_right": {
                    "lat": 25,
                    "lon": -65
                  }
                }
              }
            }
          ],
          "minimum_should_match" : 1
        }
      },
      "aggs": {
        "user": {
          "terms": {
            "field": "user_id",
            "min_doc_count": 2
          },
          "aggs": {
            "country_count": {
              "filters": {
                "filters": {
                  "Filter_1": {
                    "geo_bounding_box": {
                      "geo_point": {
                        "top_left": {
                          "lat": 0,
                          "lon": -45
                        },
                        "bottom_right": {
                          "lat": -25,
                          "lon": -30
                        }
                      }
                    }
                  },
                  "Filter_2": {
                    "geo_bounding_box": {
                      "geo_point": {
                        "top_left": {
                          "lat": 50,
                          "lon": -125
                        },
                        "bottom_right": {
                          "lat": 25,
                          "lon": -65
                        }
                      }
                    }
                  }
                }
              }
            },
    		"bucket_filter": {
    		  "bucket_selector": {
    		    "buckets_path": {
    		      "recordCount": "_count"
    		    },
    			"script": "params.recordCount > 0"
    		  }
    		}
          }
        }
      }
    }

Output:

           "user": {
               "doc_count_error_upper_bound": 737,
               "sum_other_doc_count": 300365,
               "buckets": [
                   {
                       "key": 10459017,
                       "doc_count": 2130,
                       "country_count": {
                           "buckets": {
                               "Filter_1": {
                                   "doc_count": 0
                               },
                               "Filter_2": {
                                   "doc_count": 2130
                               }
                           }
                       }
                   },...

Thanks for your help.

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