# Paging bug with bucket sort aggregation

**URL:** <https://discuss.elastic.co/t/paging-bug-with-bucket-sort-aggregation/119670>\
**Category:** Elasticsearch\
**Created:** [February 13, 2018, 4:06pm UTC](https://discuss.elastic.co/t/paging-bug-with-bucket-sort-aggregation/119670 "2018-02-13T16:06:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Field](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_field/32/26599_2.png) [@Matthew\_Field](https://discuss.elastic.co/u/Matthew_Field)\
**Post date:** [February 13, 2018, 4:06pm UTC](https://discuss.elastic.co/t/paging-bug-with-bucket-sort-aggregation/119670/1 "2018-02-13T16:06:34Z")

</div>

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.

```auto

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
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 13, 2018, 4:06pm UTC](https://discuss.elastic.co/t/paging-bug-with-bucket-sort-aggregation/119670/2 "2018-03-13T16:06:39Z")

</div>

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