# Facet\_filter simple example does not work

**URL:** <https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263>\
**Category:** Elasticsearch\
**Created:** [March 22, 2013, 2:17pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263 "2013-03-22T14:17:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 22, 2013, 2:17pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/1 "2013-03-22T14:17:25Z")

</div>

Hi All,

I'm trying to execute statistical facet with filter. So I'm using  
"facet\_filter" without success.  
Could you please help me with correct query?  
Or maybe there is something else wrong?

My ElasticSearch version is 0.20.2.

My document structure/mapping is:  
{"wch1":{"properties":{"HouseCode":{"type":"string",  
"index":"not\_analyzed"},"numbers":{"type":"long"},"period":{"type":"string",  
"index":"not\_analyzed"}}}}

Example document:  
{HouseCode:"AB", period:["2013-04-03|2013-04-24", "2013-05-03|2013-05-24",  
"2013-06-03|2013-06-24"], numbers:[3,13,7,33,179,170987]}

My query/facet is:  
curl -XGET [http://localhost:9200/test\_wch/wch1/\_search](http://localhost:9200/test_wch/wch1/_search) -d '{"facets" : {  
"fname" : {"statistical" : {"field":"numbers"} }, "facet\_filter" : {"term"  
: { "HouseCode" : "AB"}} } } }'

And I get error:  
... Parse Failure [No facet type found for [term]]]; }]","status":500}

Please help. Thanks in advance.

Best Regards,  
Waldek

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 22, 2013, 3:26pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/2 "2013-03-22T15:26:00Z")

</div>

The facet\_filter block needs to be under the fname facet declaration  
(adjacent to the 'statistical' type)

{  
"facets": {  
"fname": {  
"statistical": {  
"field": "numbers"  
},  
"facet\_filter": {  
"term": {  
"HouseCode": "ab"  
}  
}  
}  
}  
}  
}'

--  
Ivan

On Fri, Mar 22, 2013 at 7:17 AM, [waldemar@pureholidayhomes.com](mailto:waldemar@pureholidayhomes.com) wrote:

> Hi All,
> 
> I'm trying to execute statistical facet with filter. So I'm using  
> "facet\_filter" without success.  
> Could you please help me with correct query?  
> Or maybe there is something else wrong?
> 
> My Elasticsearch version is 0.20.2.
> 
> My document structure/mapping is:  
> {"wch1":{"properties":{"HouseCode":{"type":"string",  
> "index":"not\_analyzed"},"numbers":{"type":"long"},"period":{"type":"string",  
> "index":"not\_analyzed"}}}}
> 
> Example document:  
> {HouseCode:"AB", period:["2013-04-03|2013-04-24", "2013-05-03|2013-05-24",  
> "2013-06-03|2013-06-24"], numbers:[3,13,7,33,179,170987]}
> 
> My query/facet is:  
> curl -XGET [http://localhost:9200/test\_wch/wch1/\_search](http://localhost:9200/test_wch/wch1/_search) -d '{"facets" : {  
> "fname" : {"statistical" : {"field":"numbers"} }, "facet\_filter" : {"term"  
> : { "HouseCode" : "AB"}} } } }'
> 
> And I get error:  
> ... Parse Failure [No facet type found for [term]]]; }]","status":500}
> 
> Please help. Thanks in advance.
> 
> Best Regards,  
> Waldek
> 
> --  
> 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:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 22, 2013, 4:04pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/3 "2013-03-22T16:04:26Z")

</div>

Thanks Ivan for your reply.

It helped, but now I have other problem, the statistic is taken from all  
documents, not from that which have HouseCode = AB.  
How should I filter a statistical facet for specyfic HouseCode or other  
fields conditions?

Best Regards,  
Waldek

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 22, 2013, 4:08pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/4 "2013-03-22T16:08:50Z")

</div>

A term filter/query does an exact match, so the term filtered on must have  
the correct case. Not sure how I ended up lowercasing AB since all I did  
was copy-n-paste.

--  
Ivan

On Fri, Mar 22, 2013 at 9:04 AM, [waldemar@pureholidayhomes.com](mailto:waldemar@pureholidayhomes.com) wrote:

> Thanks Ivan for your reply.
> 
> It helped, but now I have other problem, the statistic is taken from all  
> documents, not from that which have HouseCode = AB.  
> How should I filter a statistical facet for specyfic HouseCode or other  
> fields conditions?
> 
> Best Regards,  
> Waldek
> 
> --  
> 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:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 22, 2013, 4:17pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/5 "2013-03-22T16:17:28Z")

</div>

I think it's not the lowercase/uppercase problem if the codes are exact.  
I want to compute facet only on specific (filtered) documents and I'm not  
able to do that with filter. I can only do that with query, which I don't  
wont.  
So is it possible to filter facet ? To do facet on filtered documents?

On Friday, 22 March 2013 17:08:50 UTC+1, Ivan Brusic wrote:

> A term filter/query does an exact match, so the term filtered on must have  
> the correct case. Not sure how I ended up lowercasing AB since all I did  
> was copy-n-paste.
> 
> --  
> Ivan
> 
> On Fri, Mar 22, 2013 at 9:04 AM, \<[wald...@pureholidayhomes.com](mailto:wald...@pureholidayhomes.com)\<javascript:\>
> 
> > wrote:
> 
> > Thanks Ivan for your reply.
> > 
> > It helped, but now I have other problem, the statistic is taken from all  
> > documents, not from that which have HouseCode = AB.  
> > How should I filter a statistical facet for specyfic HouseCode or other  
> > fields conditions?
> > 
> > Best Regards,  
> > Waldek
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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:** ![waldemar](https://avatars.discourse-cdn.com/v4/letter/w/bcef8e/32.png) [@waldemar](https://discuss.elastic.co/u/waldemar)\
**Post date:** [March 22, 2013, 4:56pm UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/6 "2013-03-22T16:56:28Z")

</div>

After a very careful examination of the output.  
It turns out that everything is fine.  
Construction for the queries where, the query is by default "match\_all" ES  
shows / returns all documents, but the facet is calculated according to the  
filter. (So be warned.)  
It turns out that facet\_filter works correctly.

Best for all,  
and Ivan thanks for your help.

Greets,  
Waldek

--  
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:45am UTC](https://discuss.elastic.co/t/facet-filter-simple-example-does-not-work/11263/7 "2017-07-06T02:45:04Z")

</div>


