Calculate size of top hit in elasticsearch based on number of buckets

I'm filtering documents based on top left and bottom right coordinates and after that using geohash forming buckets. Each bucket has fixed number of top documents in it. I want to always show for example 60 documents, equally populated in buckets. So if in my result for some geohash precision I have 2 buckets I want to have 30 top hit results in each bucket. Or if result has 10 buckets I want to have 6 top hit results in each bucket. Is there any way to have calculated size of top hits based on number of buckets?

My query:

{
  "query": {
    "bool": {
      "must": {
        "terms": {
          "category": [
            6
          ]
        }
      },
      "filter": {
        "geo_bounding_box": {
          "type": "indexed",
          "geoLocations.geoLocation": {
            "top_left": {
              "lat": 46.383606,
              "lon": 17.780508
            },
            "bottom_right": {
              "lat": 41.014818,
              "lon": 28.931074
            }
          }
        }
      }
    }
  },
  "aggregations": {
    "large-grid": {
      "geohash_grid": {
        "field": "geoLocations.geoLocation",
        "precision": 5
      },
      "aggs":{
          "document":{
            "top_hits": {
              "sort": [
                {"geoLocations.priority": {
                  "order": "desc"
                }}
                ], 
              "size": 1 <----- this is what I want to be calculated based on number of buckets in geohash aggregation
            }
          }
        }
    }
  }
}

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