# Search filter in queries and not facets

**URL:** <https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142>\
**Category:** Elasticsearch\
**Created:** [March 22, 2011, 5:38am UTC](https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142 "2011-03-22T05:38:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [March 22, 2011, 5:38am UTC](https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142/1 "2011-03-22T05:38:06Z")

</div>

I was taking a look at issue 650:  
[https://github.com/elasticsearch/elasticsearch/issues/650](https://github.com/elasticsearch/elasticsearch/issues/650) and also a  
previous related one 499:  
[https://github.com/elasticsearch/elasticsearch/issues/499](https://github.com/elasticsearch/elasticsearch/issues/499) but I think it's  
not enough for a use case I am having and I would like to listen some  
opinions, there is always the possibility that I am understanding it all  
wrong 🙂

As the example in 650 showed, it works fine for a single facet, "tag", but  
let's expand the example to two facets at the same time, for example a new  
field called "date", with values {today, yesterday}, I gisted it here

> <https://gist.github.com/sebaes/880814>

Continuing with the example, I would like to search for:

message=something, tag=blue, date=yesterday

Faceting by tag and date.

I would have to use a query with term message=something, include an and  
"filter" with tag=blue, and date=yesterday filters, so far so good.

The problem is that for the "tag" facet I would have to include a  
"facet\_filter" with a filtered query of "message=something" and  
"date=yesterday", effectively all the queries plus filters except the one  
used in this facet. Similar for "date" facet, I would have to include a  
"facet\_filter" with a filtered query of "message=something" and "tag=blue".

This gets exponential with many facets at the same time, I am even scared to  
ask how is the parsing and execution done.

I don't know if it's even doable, but I was thinking in something like an  
integrated faceting-filter, that joins both components. It would facet  
restricted by every other query+filter (but not his own filter value), and  
would add a filter to reduce the hit results.

As a concrete example to see a real use case, go to Amazon:

> <https://www.amazon.com/gp/search/ref=sr_nr_scat_1264866011_ln?rh=n%3A1264866011%2Ck%3Amp3&keywords=mp3&ie=UTF8&qid=1300769979&scn=1264866011&h=492973c59cda11820161a14b6b76464c95673c62#/ref=sr_nr_p_n_feature_four_bro_1?rh=n%3A172282%2Cn%3A!493964%2Cn%3A172623%2Cn%3A172630%2Cn%3A1264866011%2Ck%3Amp3%2Cp_n_feature_five_browse-bin%3A2204843011%2Cp_n_feature_four_browse-bin%3A676331011&bbn=1264866011&keywords=mp3&ie=UTF8&qid=1300770039>

Yes, an ugly link, but see how the faceting is done in the left, I clicked  
in "Under 1 GB" and "Line-in Recording", both facets at the same time, but  
the count of "Capacity", where "Under 1 GB" belongs, are kept independently  
of each other, but in relation with the other facet "Line-in Recording" and  
also my text query "mp3".

Sorry for the long post, any ideas would be great,  
Sebastian.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 22, 2011, 8:33am UTC](https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142/2 "2011-03-22T08:33:03Z")

</div>

Why would you need to pass a facet\_filter that includes the message=something? You will already get only hits for that since its your query.

If you want the facet selection to be applied to a specific facet, you add it as a facet filter. If you don't, you don't.

This allows for great flexibility. Where you can slice and dice the facets and decide which ones show the count of what (think also of a case with a navigation bar).

If you still have problems, post your curl understanding of how to do it, and we can continue from there.  
On Tuesday, March 22, 2011 at 7:38 AM, Sebastian Gavarini wrote:

> I was taking a look at issue 650: [Search: Allow to pass a search filter, applying only on the query (and not on facets for example) · Issue #650 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/650) and also a previous related one 499: [Multi-select facets · Issue #499 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/499) but I think it's not enough for a use case I am having and I would like to listen some opinions, there is always the possibility that I am understanding it all wrong 🙂
> 
> As the example in 650 showed, it works fine for a single facet, "tag", but let's expand the example to two facets at the same time, for example a new field called "date", with values {today, yesterday}, I gisted it here [Search filter in queries and not facets, expanded example from issue 650 · GitHub](https://gist.github.com/880814)
> 
> Continuing with the example, I would like to search for:
> 
> message=something, tag=blue, date=yesterday
> 
> Faceting by tag and date.
> 
> I would have to use a query with term message=something, include an and "filter" with tag=blue, and date=yesterday filters, so far so good.
> 
> The problem is that for the "tag" facet I would have to include a "facet\_filter" with a filtered query of "message=something" and "date=yesterday", effectively all the queries plus filters except the one used in this facet. Similar for "date" facet, I would have to include a "facet\_filter" with a filtered query of "message=something" and "tag=blue".
> 
> This gets exponential with many facets at the same time, I am even scared to ask how is the parsing and execution done.
> 
> I don't know if it's even doable, but I was thinking in something like an integrated faceting-filter, that joins both components. It would facet restricted by every other query+filter (but not his own filter value), and would add a filter to reduce the hit results.
> 
> As a concrete example to see a real use case, go to Amazon: [Amazon.com : mp3](http://www.amazon.com/gp/search/ref=sr_nr_scat_1264866011_ln?rh=n%3A1264866011%2Ck%3Amp3&keywords=mp3&ie=UTF8&qid=1300769979&scn=1264866011&h=492973c59cda11820161a14b6b76464c95673c62#/ref=sr_nr_p_n_feature_four_bro_1?rh=n%3A172282%2Cn%3A!493964%2Cn%3A172623%2Cn%3A172630%2Cn%3A1264866011%2Ck%3Amp3%2Cp_n_feature_five_browse-bin%3A2204843011%2Cp_n_feature_four_browse-bin%3A676331011&bbn=1264866011&keywords=mp3&ie=UTF8&qid=1300770039)
> 
> Yes, an ugly link, but see how the faceting is done in the left, I clicked in "Under 1 GB" and "Line-in Recording", both facets at the same time, but the count of "Capacity", where "Under 1 GB" belongs, are kept independently of each other, but in relation with the other facet "Line-in Recording" and also my text query "mp3".
> 
> Sorry for the long post, any ideas would be great,  
> Sebastian.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [March 22, 2011, 10:41am UTC](https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142/3 "2011-03-22T10:41:19Z")

</div>

Hi Shay,

I can see it now, there's no need for the query again, I got it wrong at  
first. It's a very flexible way to do it actually.

Thanks,  
Sebastian.

On Tue, Mar 22, 2011 at 5:33 AM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Why would you need to pass a facet\_filter that includes the  
> message=something? You will already get only hits for that since its your  
> query.
> 
> If you want the facet selection to be applied to a specific facet, you add  
> it as a facet filter. If you don't, you don't.
> 
> This allows for great flexibility. Where you can slice and dice the facets  
> and decide which ones show the count of what (think also of a case with a  
> navigation bar).
> 
> If you still have problems, post your curl understanding of how to do it,  
> and we can continue from there.
> 
> On Tuesday, March 22, 2011 at 7:38 AM, Sebastian Gavarini wrote:
> 
> I was taking a look at issue 650:  
> [Search: Allow to pass a search filter, applying only on the query (and not on facets for example) · Issue #650 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/650) and also a  
> previous related one 499:  
> [Multi-select facets · Issue #499 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/499) but I think it's  
> not enough for a use case I am having and I would like to listen some  
> opinions, there is always the possibility that I am understanding it all  
> wrong 🙂
> 
> As the example in 650 showed, it works fine for a single facet, "tag", but  
> let's expand the example to two facets at the same time, for example a new  
> field called "date", with values {today, yesterday}, I gisted it here  
> [Search filter in queries and not facets, expanded example from issue 650 · GitHub](https://gist.github.com/880814)
> 
> Continuing with the example, I would like to search for:
> 
> message=something, tag=blue, date=yesterday
> 
> Faceting by tag and date.
> 
> I would have to use a query with term message=something, include an and  
> "filter" with tag=blue, and date=yesterday filters, so far so good.
> 
> The problem is that for the "tag" facet I would have to include a  
> "facet\_filter" with a filtered query of "message=something" and  
> "date=yesterday", effectively all the queries plus filters except the one  
> used in this facet. Similar for "date" facet, I would have to include a  
> "facet\_filter" with a filtered query of "message=something" and "tag=blue".
> 
> This gets exponential with many facets at the same time, I am even scared  
> to ask how is the parsing and execution done.
> 
> I don't know if it's even doable, but I was thinking in something like an  
> integrated faceting-filter, that joins both components. It would facet  
> restricted by every other query+filter (but not his own filter value), and  
> would add a filter to reduce the hit results.
> 
> As a concrete example to see a real use case, go to Amazon:  
> [Amazon.com : mp3](http://www.amazon.com/gp/search/ref=sr_nr_scat_1264866011_ln?rh=n%3A1264866011%2Ck%3Amp3&keywords=mp3&ie=UTF8&qid=1300769979&scn=1264866011&h=492973c59cda11820161a14b6b76464c95673c62#/ref=sr_nr_p_n_feature_four_bro_1?rh=n%3A172282%2Cn%3A!493964%2Cn%3A172623%2Cn%3A172630%2Cn%3A1264866011%2Ck%3Amp3%2Cp_n_feature_five_browse-bin%3A2204843011%2Cp_n_feature_four_browse-bin%3A676331011&bbn=1264866011&keywords=mp3&ie=UTF8&qid=1300770039)
> 
> Yes, an ugly link, but see how the faceting is done in the left, I clicked  
> in "Under 1 GB" and "Line-in Recording", both facets at the same time, but  
> the count of "Capacity", where "Under 1 GB" belongs, are kept independently  
> of each other, but in relation with the other facet "Line-in Recording" and  
> also my text query "mp3".
> 
> Sorry for the long post, any ideas would be great,  
> Sebastian.

---

<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, 4:09am UTC](https://discuss.elastic.co/t/search-filter-in-queries-and-not-facets/4142/4 "2017-07-06T04:09:30Z")

</div>


