# Paginate by unique field count

**URL:** <https://discuss.elastic.co/t/paginate-by-unique-field-count/211582>\
**Category:** Elasticsearch\
**Created:** [December 12, 2019, 7:35am UTC](https://discuss.elastic.co/t/paginate-by-unique-field-count/211582 "2019-12-12T07:35:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EOX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eox/32/59250_2.png) [@EOX](https://discuss.elastic.co/u/EOX)\
**Post date:** [December 12, 2019, 7:35am UTC](https://discuss.elastic.co/t/paginate-by-unique-field-count/211582/1 "2019-12-12T07:35:25Z")

</div>

Hi all,

Say I have a Venue and Event entity.

On the search page, I want to show paginated list of Venues and corresponding Events at that venue in 7 days (One to Many).

One simple approach is to do a global search for Events happening in 7 days.. and then do groupby in the backend. However, this makes pagination difficult because I don't want to paginate on the Events but rather their Venue property (because I want to show 20 venues per page)

Ideally, I want to paginate on Event.venueId or Event.venue.id. Is this possible ?

I have looked into some techniques like aggregation partition, parent/child, but they all seem overly compex or not ideal.

I'm working with Elasticsearch v 6.4.3.

Thanks

---

<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:** [December 12, 2019, 9:02am UTC](https://discuss.elastic.co/t/paginate-by-unique-field-count/211582/2 "2019-12-12T09:02:09Z")

</div>

hey,

the `join` datatype sounds like a valid solution to this approach (aka parent/child). However, if you are able to include all the venue information in each event, then you can simply search for events and use [field collapsing](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-collapse) on the venue id for example.

This data remodelling would remove the need for more than a single query.

--Alex

---

<div class="post-metadata">

**Author:** ![EOX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eox/32/59250_2.png) [@EOX](https://discuss.elastic.co/u/EOX)\
**Post date:** [December 13, 2019, 12:14am UTC](https://discuss.elastic.co/t/paginate-by-unique-field-count/211582/3 "2019-12-13T00:14:29Z")

</div>

Thanks Alex!

Field collapsing did the job!

---

<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:** [January 10, 2020, 12:14am UTC](https://discuss.elastic.co/t/paginate-by-unique-field-count/211582/4 "2020-01-10T00:14:41Z")

</div>

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