# Facets only on hits actually returned

**URL:** <https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410>\
**Category:** Elasticsearch\
**Created:** [January 25, 2014, 1:04am UTC](https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410 "2014-01-25T01:04:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tinou\_Bao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tinou_bao/32/1736_2.png) [@Tinou\_Bao](https://discuss.elastic.co/u/Tinou_Bao)\
**Post date:** [January 25, 2014, 1:04am UTC](https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410/1 "2014-01-25T01:04:06Z")

</div>

This may sound like a strange question but is there a way to get facets  
only for the hits actually returned? So for example, if there are 100k  
total hits but I only asked for 100 in the size parameter, I only want the  
facets on the 100 actually returned. Obviously I could just go through the  
100 results and do the aggregation myself but wanted to see if there was a  
way to let elasticsearch/lucene do it. I know there is facet scopes and  
facet filters but I just need the facets on the **actual** returned hits.  
much thanks

-T

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 25, 2014, 6:37am UTC](https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410/2 "2014-01-25T06:37:52Z")

</div>

I think that if you add a limit filter in your FilteredQuery it should work.  
But only for the 1st page.

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 25 janv. 2014 à 02:04, Tinou Bao [tinou.bao@gmail.com](mailto:tinou.bao@gmail.com) a écrit :

This may sound like a strange question but is there a way to get facets only for the hits actually returned? So for example, if there are 100k total hits but I only asked for 100 in the size parameter, I only want the facets on the 100 actually returned. Obviously I could just go through the 100 results and do the aggregation myself but wanted to see if there was a way to let elasticsearch/lucene do it. I know there is facet scopes and facet filters but I just need the facets on the **actual** returned hits. much thanks

## -T

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/FDCBABDC-E790-483F-B47B-7C82ACD8B2EA%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/FDCBABDC-E790-483F-B47B-7C82ACD8B2EA%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 25, 2014, 7:59am UTC](https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410/3 "2014-01-25T07:59:02Z")

</div>

There is an open issue for this request, but no comment from the  
elasticsearch team in two years:

> <https://github.com/elastic/elasticsearch/issues/2040>
>
> See
> https://groups.google.com/d/msg/elasticsearch/OZsc5ofNhag/9JfwSy-CEMwJ where… Shay says "...with the design of the facets, if shouldn't be hard to implement..."

I have a vague how to implement such as feature with the old facets, but  
not with the new aggregation framework. No clue if it would make the task  
easier or not. Perhaps I should look into it.

Ivan

On Fri, Jan 24, 2014 at 10:37 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> I think that if you add a limit filter in your FilteredQuery it should  
> work.  
> But only for the 1st page.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 25 janv. 2014 à 02:04, Tinou Bao [tinou.bao@gmail.com](mailto:tinou.bao@gmail.com) a écrit :
> 
> This may sound like a strange question but is there a way to get facets  
> only for the hits actually returned? So for example, if there are 100k  
> total hits but I only asked for 100 in the size parameter, I only want the  
> facets on the 100 actually returned. Obviously I could just go through the  
> 100 results and do the aggregation myself but wanted to see if there was a  
> way to let elasticsearch/lucene do it. I know there is facet scopes and  
> facet filters but I just need the facets on the **actual** returned hits.  
> much thanks
> 
> -T
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/abd1de9e-b85f-4ff1-909f-43226dabbda4%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/FDCBABDC-E790-483F-B47B-7C82ACD8B2EA%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/FDCBABDC-E790-483F-B47B-7C82ACD8B2EA%40pilato.fr)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCKEpc9DcGUiG9TyP9CXaOhHREqRsi8LRBfywwDjtw\_-w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCKEpc9DcGUiG9TyP9CXaOhHREqRsi8LRBfywwDjtw_-w%40mail.gmail.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, 1:54am UTC](https://discuss.elastic.co/t/facets-only-on-hits-actually-returned/15410/4 "2017-07-06T01:54:50Z")

</div>


