# Difference between two facets

**URL:** https://discuss.elastic.co/t/difference-between-two-facets/12347
**Category:** Elasticsearch
**Created:** [June 10, 2013, 8:27pm UTC](https://discuss.elastic.co/t/difference-between-two-facets/12347 "2013-06-10T20:27:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jurg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jurg/32/2289_2.png) [@jurg](https://discuss.elastic.co/u/jurg)
#### Post date: [June 10, 2013, 8:27pm UTC](https://discuss.elastic.co/t/difference-between-two-facets/12347/1 "2013-06-10T20:27:27Z")

</div>

Hi all,

Can someone help me understand why we get different results form the  
following two queries (or tell me where I can find an explanation)

{  
"from" : 0, "size" : 0,  
"query": {  
"filtered": {  
"query": {  
"term": {  
"@fields.check\_id":  
"680c814c-9d97-42e5-8d6f-a463195c98cf"  
}  
},  
"filter": {  
"range": {  
"@timestamp": {  
"from": "now-1M",  
"to": "now"  
}  
}  
}  
}  
},  
"facets": {  
"uptime": {  
"terms": {  
"field": "@fields.result"  
}  
}  
}  
}

and this

{  
"from" : 0, "size" : 0,  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"range": {  
"@timestamp": {  
"from": "now-1M",  
"to": "now"  
}  
}  
}  
}  
},  
"facets": {  
"uptime": {  
"terms": {  
"field": "@fields.result"  
},  
"facet\_filter": {  
"term": {  
"@fields.check\_id":  
"680c814c-9d97-42e5-8d6f-a463195c98cf"  
}  
}  
}  
}  
}

Thanks,  
Jurg.

--  
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: ![Zhoutuo\_Yang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zhoutuo_yang/32/2211_2.png) [@Zhoutuo\_Yang](https://discuss.elastic.co/u/Zhoutuo_Yang)
#### Post date: [June 11, 2013, 12:40am UTC](https://discuss.elastic.co/t/difference-between-two-facets/12347/2 "2013-06-11T00:40:26Z")

</div>

As far as I know,  
the first query would only facet on 680c814c-9d97-42e5-8d6f-a463195c98cf.  
Your second facet calculation will not  
include 680c814c-9d97-42e5-8d6f-a463195c98cf, which is opposite, you might  
confuse with  
filter facet.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Monday, June 10, 2013 1:27:27 PM UTC-7, Jurg van Vliet wrote:

> Hi all,
> 
> Can someone help me understand why we get different results form the  
> following two queries (or tell me where I can find an explanation)
> 
> {  
> "from" : 0, "size" : 0,  
> "query": {  
> "filtered": {  
> "query": {  
> "term": {  
> "@fields.check\_id":  
> "680c814c-9d97-42e5-8d6f-a463195c98cf"  
> }  
> },  
> "filter": {  
> "range": {  
> "@timestamp": {  
> "from": "now-1M",  
> "to": "now"  
> }  
> }  
> }  
> }  
> },  
> "facets": {  
> "uptime": {  
> "terms": {  
> "field": "@fields.result"  
> }  
> }  
> }  
> }
> 
> and this
> 
> {  
> "from" : 0, "size" : 0,  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "range": {  
> "@timestamp": {  
> "from": "now-1M",  
> "to": "now"  
> }  
> }  
> }  
> }  
> },  
> "facets": {  
> "uptime": {  
> "terms": {  
> "field": "@fields.result"  
> },  
> "facet\_filter": {  
> "term": {  
> "@fields.check\_id":  
> "680c814c-9d97-42e5-8d6f-a463195c98cf"  
> }  
> }  
> }  
> }  
> }
> 
> Thanks,  
> Jurg.

--  
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: ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)
#### Post date: [June 11, 2013, 8:33am UTC](https://discuss.elastic.co/t/difference-between-two-facets/12347/3 "2013-06-11T08:33:23Z")

</div>

Hi Jurg,

The facet part should return the same. The difference is in the hits  
section of the result.

When you use a filter within the query clause, it modifies the set of  
documents that the query matches. This means that both the hits section and  
the facet get affected by it.

Putting the filter as a facet\_filter under a facet means that the set of  
document is filtered before being analysed but this has affect _only_ on  
this specific facet, not the query results.

Does this explain what you are seeing?

Cheers,  
Boaz

On Monday, June 10, 2013 10:27:27 PM UTC+2, Jurg van Vliet wrote:

> Hi all,
> 
> Can someone help me understand why we get different results form the  
> following two queries (or tell me where I can find an explanation)
> 
> {  
> "from" : 0, "size" : 0,  
> "query": {  
> "filtered": {  
> "query": {  
> "term": {  
> "@fields.check\_id":  
> "680c814c-9d97-42e5-8d6f-a463195c98cf"  
> }  
> },  
> "filter": {  
> "range": {  
> "@timestamp": {  
> "from": "now-1M",  
> "to": "now"  
> }  
> }  
> }  
> }  
> },  
> "facets": {  
> "uptime": {  
> "terms": {  
> "field": "@fields.result"  
> }  
> }  
> }  
> }
> 
> and this
> 
> {  
> "from" : 0, "size" : 0,  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "range": {  
> "@timestamp": {  
> "from": "now-1M",  
> "to": "now"  
> }  
> }  
> }  
> }  
> },  
> "facets": {  
> "uptime": {  
> "terms": {  
> "field": "@fields.result"  
> },  
> "facet\_filter": {  
> "term": {  
> "@fields.check\_id":  
> "680c814c-9d97-42e5-8d6f-a463195c98cf"  
> }  
> }  
> }  
> }  
> }
> 
> Thanks,  
> Jurg.

--  
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:31am UTC](https://discuss.elastic.co/t/difference-between-two-facets/12347/4 "2017-07-06T02:31:52Z")

</div>


