Paging bug with bucket sort aggregation

I am trying to page the results of a terms aggregation using a bucket sort aggregation.

I am using the query below to sort the buckets by the sum of the scores in order to list the categories by order of relevance. I then want to page the results and to do that i am using a bucket sort aggregation.

The problem is that the when I use "from":1 the aggregation truncates 2 results, when i use from:2 it truncates 4 results. So apparently it is at least predictable, but I don't understand why it is truncating exactly double the results I am specifying.

I am using a work around to get my results:

for 0-10 i use from:0 size:10:
for 11-20 I use from:5 size 15
fro 21-30 I user from:10 size 20

But i am not comfortable with the fact that it is truncating an unexpected value.

Thanks in advance for any help you could give.


POST _search?
{
  "size": 0,
  "query": {
    "bool": {
     
      "should": [
        {
          "match": {
            "bodyText": "deep learning"
          }
        },
        {
          "match": {
            "bodyText": "intelligence"
          }
        }
      ],
      
      "boost": 1
    
    }
  },
  "aggs": {
    "top-connections": {
      "terms": {
        "field": "data.category.keyword",
      
        "order": {
          "sum_score": "desc"
        },
        "size": 200
      },
      "aggs": {
      
        "sum_score": {
          "sum": {
            "script": "_score"
          }
        },
        "sales_bucket_sort": {
          "bucket_sort": {
            "sort": [
              {
                "sum_score": {
                  "order": "desc"
                }
              }
            ],
            "size": 5,
            "from":1
          }
        }
      }
    }
  }
}

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