'Filter documents prior to bucketing using GeoTile Aggregation in Elasticsearch

I am looking for an example where documents are filtered prior to bucketing via the GeoTile aggregation. For example, I would like to have buckets that hold the number of documents where some value is greater than x. Any pointers would be appreciated. Right now I have:

{
    "aggs": {
        "avg_my_field": {
            "avg": {
                "field": "properties.my_field"
            }
        },
        "aggs": {
            "large-grid": {
                "geotile_grid": {
                    "field": "coordinates",
                    "precision": 8
                }
            }
        }
    }
}

I don't know where to go from here. Any pointers would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source