Using a geo_bound aggregation together with pagination

Hi all,

When using a geo_bound aggregation (ie. the smallest window of coordinates to display all results) and pagination (x documents per page) together, I am wondering if the aggregation is run on the subset of results selected by the pagination or the complete data set ?

For example, if I search all documents within a given radius, and select top 10 documents. Will the aggregation use all documents as calculation reference, or use the top 10 only ?

I was not able to find that information from the docs...
Thanks !


Aggregations run over all documents returned but the query not just the hits (the page of results). So for example if you run a query which matches 5000 documents but ask for from:0, size:10 you will get the 10 hits (results) back but the aggregations will be run over all 5000 matching documents.

Hope that helps

Great news! Thanks for the answer ! :wink:

Now, I am facing another problem, can I add a central point to the query ? To be considered as extra point?

For example, when I search for a given city and all my points are situated in the souther half, I would like to show a map containing both center of the city and all available results. Using the geo_bound aggregations, it does not include the original point I was looking for.

Is this possible?

Unfortunately no you can't have the aggregation include the original query point as the aggregations don't know anything about the actual query, they are only given the documents matching the query. However, in your app you could take the output of your geo_bounds query and extend the bounding box if the point is not inside it. Something like this (in pseudocode):

if ( < { =

if (geo_bounds.bottom > {
    geobounds.bottom =

if (geo_bounds.right < query.lon()) {
    geobounds.right = query.lon()

if (geo_bounds.left > query.lon()) {
    geobounds.left = query.lon()

Thanks, I will definitely try this strategy ! I'll let you know if this worked !