# Pagination over facets values

**URL:** <https://discuss.elastic.co/t/pagination-over-facets-values/7564>\
**Category:** Elasticsearch\
**Created:** [May 4, 2012, 12:14pm UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564 "2012-05-04T12:14:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUsers](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@ElasticUsers](https://discuss.elastic.co/u/ElasticUsers)\
**Post date:** [May 4, 2012, 12:14pm UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564/1 "2012-05-04T12:14:40Z")

</div>

Hi Team,

Kindly let us know can we paginate over facets values. Our requirement is to retrieve all the values for a particular field. Since we may have hundreds of thousands of values for a particular field,it would be nice if some pagination API is available in ES, so that we could get all the available values not at one go but in smaller chunks of 50,100, 200...

Currently we are using TermsFacetBuilder to get top 100 or 200 values for a field but it has limitations as the values grows large in numbers - memory consumption would be high. The following snippet shows how are we forming queries for facets -

for (String tf : termFacets) {  
TermsFacetBuilder termsFacetBuilder = FacetBuilders.termsFacet(tf);  
termsFacetBuilder.field(tf);  
[//termsFacetBuilder.allTerms](https://termsFacetBuilder.allTerms)(Boolean.TRUE);  
termsFacetBuilder.order(TermsFacet.ComparatorType.COUNT);  
termsFacetBuilder.size(topDataCount);  
builder.addFacet(termsFacetBuilder);  
}

where builder is an instance of SearchRequestBuilder and topDataCount is an int variable which holds the size. After we execute query we iterate on the SearchRespnse object to get the values of facets.

The problem with this approach is that we have to set the size in advance and for large sizes there is danger of high processing time and high memory footprint.

So please let us know if there is some pagination kind of framework available for facets to iterate over its values in smaller chunks.

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 4, 2012, 1:51pm UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564/2 "2012-05-04T13:51:11Z")

</div>

There isn't a way to paginate over terms facet.

On Fri, May 4, 2012 at 3:14 PM, ElasticUsers [kranti\_123@rediffmail.com](mailto:kranti_123@rediffmail.com)wrote:

> Hi Team,
> 
> Kindly let us know can we paginate over facets values. Our requirement is  
> to  
> retrieve all the values for a particular field. Since we may have hundreds  
> of thousands of values for a particular field,it would be nice if some  
> pagination API is available in ES, so that we could get all the available  
> values not at one go but in smaller chunks of 50,100, 200...
> 
> Currently we are using TermsFacetBuilder to get top 100 or 200 values for a  
> field but it has limitations as the values grows large in numbers - memory  
> consumption would be high. The following snippet shows how are we forming  
> queries for facets -
> 
> for (String tf : termFacets) {  
> TermsFacetBuilder termsFacetBuilder =  
> FacetBuilders.termsFacet(tf);  
> termsFacetBuilder.field(tf);  
> [//termsFacetBuilder.allTerms](https://termsFacetBuilder.allTerms)(Boolean.TRUE);
> 
> termsFacetBuilder.order(TermsFacet.ComparatorType.COUNT);  
> termsFacetBuilder.size(topDataCount);  
> builder.addFacet(termsFacetBuilder);  
> }
> 
> where builder is an instance of SearchRequestBuilder and topDataCount is an  
> int variable which holds the size. After we execute query we iterate on the  
> SearchRespnse object to get the values of facets.
> 
> The problem with this approach is that we have to set the size in advance  
> and for large sizes there is danger of high processing time and high memory  
> footprint.
> 
> So please let us know if there is some pagination kind of framework  
> available for facets to iterate over its values in smaller chunks.
> 
> Thanks
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Pagination-over-facets-values-tp3962094.html](http://elasticsearch-users.115913.n3.nabble.com/Pagination-over-facets-values-tp3962094.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Peter\_Yeremenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_yeremenko/32/2264_2.png) [@Peter\_Yeremenko](https://discuss.elastic.co/u/Peter_Yeremenko)\
**Post date:** [June 25, 2013, 6:59am UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564/3 "2013-06-25T06:59:32Z")

</div>

Since paginating terms facet is impossible what would you recommend to do?

Kranti, I am facing a very similar issue, what did you end up doing to get  
this resolved?

On Friday, May 4, 2012 7:51:11 PM UTC+6, kimchy wrote:

> There isn't a way to paginate over terms facet.
> 
> On Fri, May 4, 2012 at 3:14 PM, ElasticUsers \<[krant...@rediffmail.com](mailto:krant...@rediffmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi Team,
> > 
> > Kindly let us know can we paginate over facets values. Our requirement is  
> > to  
> > retrieve all the values for a particular field. Since we may have hundreds  
> > of thousands of values for a particular field,it would be nice if some  
> > pagination API is available in ES, so that we could get all the available  
> > values not at one go but in smaller chunks of 50,100, 200...
> > 
> > Currently we are using TermsFacetBuilder to get top 100 or 200 values for  
> > a  
> > field but it has limitations as the values grows large in numbers - memory  
> > consumption would be high. The following snippet shows how are we forming  
> > queries for facets -
> > 
> > for (String tf : termFacets) {  
> > TermsFacetBuilder termsFacetBuilder =  
> > FacetBuilders.termsFacet(tf);  
> > termsFacetBuilder.field(tf);  
> > [//termsFacetBuilder.allTerms](https://termsFacetBuilder.allTerms)(Boolean.TRUE);
> > 
> > termsFacetBuilder.order(TermsFacet.ComparatorType.COUNT);  
> > termsFacetBuilder.size(topDataCount);  
> > builder.addFacet(termsFacetBuilder);  
> > }
> > 
> > where builder is an instance of SearchRequestBuilder and topDataCount is  
> > an  
> > int variable which holds the size. After we execute query we iterate on  
> > the  
> > SearchRespnse object to get the values of facets.
> > 
> > The problem with this approach is that we have to set the size in advance  
> > and for large sizes there is danger of high processing time and high  
> > memory  
> > footprint.
> > 
> > So please let us know if there is some pagination kind of framework  
> > available for facets to iterate over its values in smaller chunks.
> > 
> > Thanks
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Pagination-over-facets-values-tp3962094.html](http://elasticsearch-users.115913.n3.nabble.com/Pagination-over-facets-values-tp3962094.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![cthoma](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cthoma](https://discuss.elastic.co/u/cthoma)\
**Post date:** [June 25, 2013, 11:55am UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564/4 "2013-06-25T11:55:23Z")

</div>

I would do a second query and would only return values for this field  
limited by size.  
The field-results could be used to do facetting.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:29am UTC](https://discuss.elastic.co/t/pagination-over-facets-values/7564/5 "2017-07-06T02:29:33Z")

</div>


