# Facet within the specified size

**URL:** <https://discuss.elastic.co/t/facet-within-the-specified-size/14965>\
**Category:** Elasticsearch\
**Created:** [December 20, 2013, 5:36am UTC](https://discuss.elastic.co/t/facet-within-the-specified-size/14965 "2013-12-20T05:36:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyprince](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rubyprince](https://discuss.elastic.co/u/rubyprince)\
**Post date:** [December 20, 2013, 5:36am UTC](https://discuss.elastic.co/t/facet-within-the-specified-size/14965/1 "2013-12-20T05:36:36Z")

</div>

Facets is very useful to get the count of the items, as a whole.

But my problem is, I want the count for the query, I am searching inside  
the size limit I am specifying. Look at the query, I am making:

curl -X GET  
'[http://localhost:9200/posts/post/\_search?from=0&size=10&pretty](http://localhost:9200/posts/post/_search?from=0&size=10&pretty)' -d '{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "_exists_:country AND content:(obama OR somalia)"  
}  
}  
}  
},  
"facets": {  
"content": {  
"terms": {  
"field": "content",  
"size": 10,  
"all\_terms": false,  
"regex": "obama|somalia",  
"regex\_flags": [  
"DOTALL",  
"CASE\_INSENSITIVE"  
]  
}  
}  
},  
"size": 10000,  
"fields": [  
"continent",  
"country",  
"id",  
"location",  
"sentiment",  
"tweet\_created\_at"  
],  
"version": true  
}'

This is the query, I am using now. But the facet content is giving count  
for the database as a whole satisfying the query string. But, I want to  
facet within the 10,000 returned.

Is there a way to facet like that?

--  
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/f5c1ccbb-3b01-492e-9357-37f14ea5e587%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f5c1ccbb-3b01-492e-9357-37f14ea5e587%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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [December 20, 2013, 5:11pm UTC](https://discuss.elastic.co/t/facet-within-the-specified-size/14965/2 "2013-12-20T17:11:19Z")

</div>

The facet will work on all the documents that satisfy the query. The size  
parameter in the query only denotes how many documents that match the query  
should be returned.

There is an issue regarding faceting only on the top n results:

> <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..."

Cheers,

Ivan

On Thu, Dec 19, 2013 at 9:36 PM, Prince [princejcet@gmail.com](mailto:princejcet@gmail.com) wrote:

> Facets is very useful to get the count of the items, as a whole.
> 
> But my problem is, I want the count for the query, I am searching inside  
> the size limit I am specifying. Look at the query, I am making:
> 
> curl -X GET '  
> [http://localhost:9200/posts/post/\_search?from=0&size=10&pretty](http://localhost:9200/posts/post/_search?from=0&size=10&pretty)' -d '{  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "query": "_exists_:country AND content:(obama OR somalia)"  
> }  
> }  
> }  
> },  
> "facets": {  
> "content": {  
> "terms": {  
> "field": "content",  
> "size": 10,  
> "all\_terms": false,  
> "regex": "obama|somalia",  
> "regex\_flags": [  
> "DOTALL",  
> "CASE\_INSENSITIVE"  
> ]  
> }  
> }  
> },  
> "size": 10000,  
> "fields": [  
> "continent",  
> "country",  
> "id",  
> "location",  
> "sentiment",  
> "tweet\_created\_at"  
> ],  
> "version": true  
> }'
> 
> This is the query, I am using now. But the facet content is giving count  
> for the database as a whole satisfying the query string. But, I want to  
> facet within the 10,000 returned.
> 
> Is there a way to facet like that?
> 
> --  
> 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/f5c1ccbb-3b01-492e-9357-37f14ea5e587%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f5c1ccbb-3b01-492e-9357-37f14ea5e587%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/CALY%3DcQAjOkXAEvG8CwhjSRKYbxSmzaJ5QAzvcmDOPGe-fjW2NQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAjOkXAEvG8CwhjSRKYbxSmzaJ5QAzvcmDOPGe-fjW2NQ%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:59am UTC](https://discuss.elastic.co/t/facet-within-the-specified-size/14965/3 "2017-07-06T01:59:55Z")

</div>


