# How to get data in chunks with collapsed fields

**URL:** <https://discuss.elastic.co/t/how-to-get-data-in-chunks-with-collapsed-fields/164881>\
**Category:** Elasticsearch\
**Created:** [January 19, 2019, 6:53am UTC](https://discuss.elastic.co/t/how-to-get-data-in-chunks-with-collapsed-fields/164881 "2019-01-19T06:53:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anshum](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@anshum](https://discuss.elastic.co/u/anshum)\
**Post date:** [January 19, 2019, 6:53am UTC](https://discuss.elastic.co/t/how-to-get-data-in-chunks-with-collapsed-fields/164881/1 "2019-01-19T06:53:01Z")

</div>

Hi,

I'm trying to apply the pagination over the data set.

USE\_CASE: My main use case is to get the data and take the top hit according to a particular field.  
Methods tried:  
Method 1: Was using the aggregations, but it's a very heavy operation and the buckets were getting sorted according to "\_score", whereas in the query I had applied some other filters. I was able to use after but unable to apply any sorting on buckets.

Method 2: Using collapseFields to get the fields, but I'm unable to use the scroll or searchAfter. The query becomes very slow when the (size + from) increases.

Is there any way I can speed it up?

---

<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:** [February 16, 2019, 7:05am UTC](https://discuss.elastic.co/t/how-to-get-data-in-chunks-with-collapsed-fields/164881/2 "2019-02-16T07:05:55Z")

</div>

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