# Field Collapsing & Pagination

**URL:** <https://discuss.elastic.co/t/field-collapsing-pagination/249936>\
**Category:** Elasticsearch\
**Created:** [September 25, 2020, 9:02am UTC](https://discuss.elastic.co/t/field-collapsing-pagination/249936 "2020-09-25T09:02:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prahalad\_Rathod](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prahalad_rathod/32/45810_2.png) [@Prahalad\_Rathod](https://discuss.elastic.co/u/Prahalad_Rathod)\
**Post date:** [September 25, 2020, 9:02am UTC](https://discuss.elastic.co/t/field-collapsing-pagination/249936/1 "2020-09-25T09:02:21Z")

</div>

I just want to know how pagination works with collapsing.  
I have below index data:

```auto
    {'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 1, "employeeName": "vijay", ...}
    {'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 2, "employeeName": "rathod", ...}
    {'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 3, "employeeName": "ajay", ...}
    {'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 4, "employeeName": "kamal", ...}
    {'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 5, "employeeName": "rahul", ...}

```

I want to get below Output with pagination

```auto
{'departmentNo': 1, 'departmentName': 'Food', 'departmentLoc': "I1", "departmentScore": "5", "employeeid" : 1, "employeeName": "vijay", ...}
{'departmentNo': 2, 'departmentName': 'Non-Food', 'departmentLoc': "I2", "departmentScore": "6", "employeeid" : 3, "employeeName": "ajay", ...}

```

So I have used below query:

```auto
{
  "query": { ... },
  "from": 0,
  "size": 5,
  "collapse": {
    "field": "departmentNo"
  }
}

```

So for **first 5 , it is giving correct results**. when I do **from =1, size =5** then it is **giving wrong results**.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 28, 2020, 9:00am UTC](https://discuss.elastic.co/t/field-collapsing-pagination/249936/2 "2020-09-28T09:00:18Z")

</div>

Hey,

instead of claiming the return of 'wrong' results, it would help if you explain what are you expecting to be returned and if you explain what you are seeing returned and what are the differences. Not everyone has the same context in mind than you, when talking about field collapsing.

Also, fully reproducible examples would help **a lot** to understand your issue instead of just snippets. This way, noone will ever try to reproduce your problem.

--Alex

---

<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:** [October 26, 2020, 9:00am UTC](https://discuss.elastic.co/t/field-collapsing-pagination/249936/3 "2020-10-26T09:00:40Z")

</div>

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