# Is Facet affects the Filtered Query Result?

**URL:** https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559
**Category:** Elasticsearch
**Created:** [September 11, 2013, 3:26pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559 "2013-09-11T15:26:17Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [September 11, 2013, 3:26pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/1 "2013-09-11T15:26:17Z")

</div>

Hi ,

I am Using Filtered Query With Facet.  
My query Structure is as Following :

{  
"query": {  
"filtered": {

```
        },
        "filter": {
            
            }
    },
   "facets": {
        "abc": {
            "terms": {
                "script_field": 

```

"doc["content\_data"].value+"+"+doc["content\_date"].value"  
}  
}  
}  
}

Here , I am Using Script Fields for my Java API to get Respected Records.  
When i add One more Element in Script field with "+" , the results i get  
are different .  
So , is Script Field in Facet affects the Actual Query result or Facet is  
just for Grouping ?

Please Suggest me , i am confused !!

Thanks ,  
Aniruddha

--  
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: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [September 11, 2013, 9:55pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/2 "2013-09-11T21:55:19Z")

</div>

Hi,

Facets don't affect the hits which are matched by your query. Changing your  
faceting script only changes the faceting part of the response.

On Wed, Sep 11, 2013 at 5:26 PM, Aniruddha Pol [aniruddhapol1@gmail.com](mailto:aniruddhapol1@gmail.com)wrote:

> Hi ,
> 
> I am Using Filtered Query With Facet.  
> My query Structure is as Following :
> 
> {  
> "query": {  
> "filtered": {
> 
> ```
> },
> "filter": {
> 
> }
> },
> "facets": {
> "abc": {
> "terms": {
> "script_field":
> 
> ```
> 
> "doc["content\_data"].value+"+"+doc["content\_date"].value"  
> }  
> }  
> }  
> }
> 
> Here , I am Using Script Fields for my Java API to get Respected Records.  
> When i add One more Element in Script field with "+" , the results i get  
> are different .  
> So , is Script Field in Facet affects the Actual Query result or Facet is  
> just for Grouping ?
> 
> Please Suggest me , i am confused !!
> 
> Thanks ,  
> Aniruddha
> 
> --  
> 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).

--  
Adrien Grand

--  
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: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [September 12, 2013, 7:16am UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/3 "2013-09-12T07:16:06Z")

</div>

Thanks Adrien .

I have one more query regarding to Facet :

In facet i am using Fields[] with size 0.  
"fields": [],  
"from": 0,  
"size": 0,  
"facets":  
{  
}

Every time its returning me 10 records for each Query.  
So , is it Default value or anywhere i am going wrong.  
Please suggest.

Thanks ,  
Aniruddha

---

<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: [September 13, 2013, 3:17pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/4 "2013-09-13T15:17:56Z")

</div>

You should not see any records for that query. Perhaps asking for an empty  
array of fields causes a bug? Can you gist the query and the output?

--  
Ivan

On Thu, Sep 12, 2013 at 12:16 AM, AniruddhaPol [aniruddhapol1@gmail.com](mailto:aniruddhapol1@gmail.com)wrote:

> Thanks Adrien .
> 
> I have one more query regarding to Facet :
> 
> In facet i am using Fields with size 0.  
> "fields": ,  
> "from": 0,  
> "size": 0,  
> "facets":  
> {  
> }
> 
> Every time its returning me 10 records for each Query.  
> So , is it Default value or anywhere i am going wrong.  
> Please suggest.
> 
> Thanks ,  
> Aniruddha
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041048.html](http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041048.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).

--  
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: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [September 24, 2013, 2:42pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/5 "2013-09-24T14:42:02Z")

</div>

Hi ,

The Query is Like :

**{  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"default\_field": "Users",  
"query": "Ani"  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"terms": {  
"City": [  
"Pune",  
"Mumbai",  
"Delhi"  
]  
}  
},  
{  
"terms": {  
"gender": [  
"male",  
"female",  
"unknown"  
]  
}  
}  
]  
}  
}  
}  
},  
"fields": [],  
"from": 0,  
"size": 0,  
"facets": {  
"City\_Facet": {  
"terms": {  
"field": "city"  
}  
}  
}  
}**

It always giving me 10 records , please review and suggest if i am wrong anywhere ?

Thanks,  
Aniruddha

---

<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: [September 25, 2013, 5:47pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/6 "2013-09-25T17:47:58Z")

</div>

Trying to wrap my head around this issue. When you say the query is giving  
you 10 records, what exactly do you mean? 10 hits returned? Total hit count  
of 10? 10 buckets in your facet?

I modified your query with fields that match my data, and requesting size:0  
and fields: returns the expected result:

"hits": {  
"total": 150,  
"max\_score": 15.479453,  
"hits":   
},

I'm on elasticsearch 0.90.2

--  
Ivan

On Tue, Sep 24, 2013 at 7:42 AM, AniruddhaPol [aniruddhapol1@gmail.com](mailto:aniruddhapol1@gmail.com)wrote:

> Hi ,
> 
> The Query is Like :
> 
> \*{  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "default\_field": "Users",  
> "query": "Ani"  
> }  
> },  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "terms": {  
> "City": [  
> "Pune",  
> "Mumbai",  
> "Delhi"  
> ]  
> }  
> },  
> {  
> "terms": {  
> "gender": [  
> "male",  
> "female",  
> "unknown"  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }  
> },  
> "fields": ,  
> "from": 0,  
> "size": 0,  
> "facets": {  
> "City\_Facet": {  
> "terms": {  
> "field": "city"  
> }  
> }  
> }  
> } \*
> 
> It always giving me 10 records , please review and suggest if i am wrong  
> anywhere ?
> 
> Thanks,  
> Aniruddha
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041761.html](http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041761.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).

--  
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: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [September 26, 2013, 6:46am UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/7 "2013-09-26T06:46:33Z")

</div>

Hi Ivan ,

Yes , it always returns 10 buckets in my Facet .  
When i tried for following it gives me more than 10 buckets in my Facet.  
So my question , **is facet by default returns 10 buckets in Facet ?**

,  
"fields": [],  
"from": 0,  
"size": 0,  
"facets": {  
"City\_Facet": {  
"terms": {  
"field": "city",  
"size" : 20  
}  
}  
}

Thanks,  
Aniruddha

---

<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: [September 26, 2013, 3:48pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/8 "2013-09-26T15:48:06Z")

</div>

Now I understand the last issue better. Your query is not returning 10  
documents, it is your facet returning 10 buckets.

Yes, 10 is the default bucket size for the terms facet. As you discovered,  
you can change the value by using the size attribute. AFAIK, it is not  
possible to return all values.

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java#L84](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java#L84)

Cheers,

Ivan

On Wed, Sep 25, 2013 at 11:46 PM, AniruddhaPol [aniruddhapol1@gmail.com](mailto:aniruddhapol1@gmail.com)wrote:

> Hi Ivan ,
> 
> Yes , it always returns 10 buckets in my Facet .  
> When i tried for following it gives me more than 10 buckets in my Facet.  
> So my question , \* is facet by default returns 10 buckets in Facet ?\*
> 
> ,  
> "fields": ,  
> "from": 0,  
> "size": 0,  
> "facets": {  
> "City\_Facet": {  
> "terms": {  
> "field": "city",  
> "size" : 20  
> }  
> }  
> }
> 
> Thanks,  
> Aniruddha
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041826.html](http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4041826.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).

--  
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: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [October 7, 2013, 8:15am UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/9 "2013-10-07T08:15:59Z")

</div>

Thanks Ivan for your Reply.  
Its really helpful for me .

Is there any way to get all values from Facet ?

Please suggest.

Thanks,  
Aniruddha

---

<div class="post-metadata">

### Author: ![AniruddhaPol](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AniruddhaPol](https://discuss.elastic.co/u/AniruddhaPol)
#### Post date: [October 10, 2013, 2:57pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/10 "2013-10-10T14:57:17Z")

</div>

Hi ,

Will default count also applicable to Query Part also without using Facet ?

Thanks,  
Aniruddha

---

<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: [October 10, 2013, 9:59pm UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/11 "2013-10-10T21:59:12Z")

</div>

As mentioned previously, there is no way to retrieve all the values.

The default query size is different from the default facet size, both of  
which default to 10.

--  
Ivan

On Thu, Oct 10, 2013 at 7:57 AM, AniruddhaPol [aniruddhapol1@gmail.com](mailto:aniruddhapol1@gmail.com)wrote:

> Hi ,
> 
> Will default count also applicable to Query Part also without using Facet ?
> 
> Thanks,  
> Aniruddha
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4042372.html](http://elasticsearch-users.115913.n3.nabble.com/Is-Facet-affects-the-Filtered-Query-Result-tp4041016p4042372.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).

--  
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:12am UTC](https://discuss.elastic.co/t/is-facet-affects-the-filtered-query-result/13559/12 "2017-07-06T02:12:57Z")

</div>


