# Facets like Booking.com

**URL:** <https://discuss.elastic.co/t/facets-like-booking-com/12685>\
**Category:** Elasticsearch\
**Created:** [July 6, 2013, 9:05am UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685 "2013-07-06T09:05:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ga\_gandhi](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@ga\_gandhi](https://discuss.elastic.co/u/ga_gandhi)\
**Post date:** [July 6, 2013, 9:05am UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685/1 "2013-07-06T09:05:11Z")

</div>

Hi,  
I am looking for faceting like [booking.com](http://booking.com).

My use case is as below:

1. We have 3 categories like (1) Gender , (2) Month , (3) Country
2. On Selection of Any category it should do AND operation for other  
selected categories options BUT for the one that is selected it should  
fetch all the facets because we want users to select options in the same  
category.

In below example, you can see:

1st image is when page is loaded.  
2nd image is when user selects July 2013 month at this time it works fine.  
And it filters the Gender properly Female (383) And Male (37)  
_BUT_  
3rd image as soon as user selects Female it resets the count to the  
original one. It MUST NOT do that. It should be 383 on selection of Female.  
No idea what is going wrong.

[https://lh4.googleusercontent.com/-HuQdA48JfqA/UdfdCvN6VsI/AAAAAAAAPrM/1uP0ZvdRBXY/s1600/Facets.png](https://lh4.googleusercontent.com/-HuQdA48JfqA/UdfdCvN6VsI/AAAAAAAAPrM/1uP0ZvdRBXY/s1600/Facets.png)

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 6, 2013, 1:00pm UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685/2 "2013-07-06T13:00:35Z")

</div>

It depends on the way you write your query.  
I assume you did a FilteredQuery, right?

You can use a Top Level filter instead of change the facet scope.

If it does not make sense, please provide your query (full curl recreation).

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 juil. 2013 à 11:05, Ankur Gandhi [ga.gandhi@gmail.com](mailto:ga.gandhi@gmail.com) a écrit :

> Hi,  
> I am looking for faceting like [booking.com](http://booking.com).
> 
> My use case is as below:
> 
> 1. We have 3 categories like (1) Gender , (2) Month , (3) Country
> 2. On Selection of Any category it should do AND operation for other selected categories options BUT for the one that is selected it should fetch all the facets because we want users to select options in the same category.
> 
> In below example, you can see:
> 
> 1st image is when page is loaded.  
> 2nd image is when user selects July 2013 month at this time it works fine. And it filters the Gender properly Female (383) And Male (37)  
> BUT  
> 3rd image as soon as user selects Female it resets the count to the original one. It MUST NOT do that. It should be 383 on selection of Female. No idea what is going wrong.
> 
> --  
> 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:** ![Christian\_Th](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Christian\_Th](https://discuss.elastic.co/u/Christian_Th)\
**Post date:** [July 6, 2013, 10:24pm UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685/3 "2013-07-06T22:24:03Z")

</div>

If i understood the problem correctly,  
you can filter each facet separately. A JSON-part for the gender facet  
could look like the following:

"facets": {  
"gender": {  
"terms": {  
"field": "gender",  
"size": 10,  
"order": "term"  
},  
"facet\_filter": {  
"and": {  
"filters": [  
{  
"or": {  
"filters": [  
{  
"term": {  
"arrival\_month": "July 2342"  
}  
}  
]  
}  
}  
]  
}  
}  
}

Each facet can be filtered by a combination of AND-and/or single/multiple  
ORFilter.

--  
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:** ![ga\_gandhi](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@ga\_gandhi](https://discuss.elastic.co/u/ga_gandhi)\
**Post date:** [July 12, 2013, 7:20am UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685/4 "2013-07-12T07:20:57Z")

</div>

Hi David,  
Thanks for your reply.

Actually I did as mentioned below:

1. I wrote a query with top level filter.
2. I applied Filter at Facet level.

Actually issue was applying previous filters to currently selected filters.  
Basically for facet calculation, for current selected category, we DID NOT  
have to apply the filter and for other facets calculations we had to apply.  
And that's where it was failing. I was not finding proper way to do it.

Now it is working fine.

The solution is as mentioned below:

1. When current category is selected, at that time I am not applying the  
filter to currently selected category facet.
2. And applying the filters to other facet categories.

That means previously applied filters will be applied to other categories  
and not to currently selected category.

If any one wants the query, let me know I will put it with proper example.

_Christian and David thanks for your help._

Thanks  
Ankur

On Sat, Jul 6, 2013 at 3:00 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> It depends on the way you write your query.  
> I assume you did a FilteredQuery, right?
> 
> You can use a Top Level filter instead of change the facet scope.
> 
> If it does not make sense, please provide your query (full curl  
> recreation).
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 juil. 2013 à 11:05, Ankur Gandhi [ga.gandhi@gmail.com](mailto:ga.gandhi@gmail.com) a écrit :
> 
> Hi,  
> I am looking for faceting like [booking.com](http://booking.com).
> 
> My use case is as below:
> 
> 1. We have 3 categories like (1) Gender , (2) Month , (3) Country
> 2. On Selection of Any category it should do AND operation for other  
> selected categories options BUT for the one that is selected it should  
> fetch all the facets because we want users to select options in the same  
> category.
> 
> In below example, you can see:
> 
> 1st image is when page is loaded.  
> 2nd image is when user selects July 2013 month at this time it works fine.  
> And it filters the Gender properly Female (383) And Male (37)  
> _BUT_  
> 3rd image as soon as user selects Female it resets the count to the  
> original one. It MUST NOT do that. It should be 383 on selection of Female.  
> No idea what is going wrong.
> 
> [https://lh4.googleusercontent.com/-HuQdA48JfqA/UdfdCvN6VsI/AAAAAAAAPrM/1uP0ZvdRBXY/s1600/Facets.png](https://lh4.googleusercontent.com/-HuQdA48JfqA/UdfdCvN6VsI/AAAAAAAAPrM/1uP0ZvdRBXY/s1600/Facets.png)
> 
> --  
> 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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/vxNTHGLYcmg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/vxNTHGLYcmg/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).

--  
Ankur G Gandhi  
contact-no: +41 0779186008  
E-mail id: [ga.gandhi@gmail.com](mailto:ga.gandhi@gmail.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).

---

<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:26am UTC](https://discuss.elastic.co/t/facets-like-booking-com/12685/5 "2017-07-06T02:26:51Z")

</div>


