Term aggregation on all document

Hi,

I'm working with Elasticsearch and I would like to be able to do something like:

  • Grouping documents into a bucket depending on a field
  • Computing on an other field
  • Using a percentile_bucket aggregation to get the repartition of those max.
  • Showing the repartition in a geotile grid

I have a beginning of a solution:

"aggs": {
    "grid": {
      "geotile_grid": {
        "field": "position",
        "precision": 10.7053792511084
      },
      "aggs": {
         "center": {
          "geo_centroid": {
            "field": "position"
          }
        },
        "grouping-path": {
          "terms": {
            "field": "context.keyword",
            "size": 10000
          },
          "aggs": {
            "max": {
              "min": {
                "field": "some_field"
              }
            }
          }
        },
        "repartition": {
          "percentiles_bucket": {
            "buckets_path": "grouping-path>max"
          }
        }
      }
    }
  }

As you can see, the term aggregation will have a limit. And, in my case, there may be more than 10000 different documents per tile. Is there a way to do something else?

Thanks!