Skip to content

Instantly share code, notes, and snippets.

@dedico
Created July 8, 2012 12:29
Show Gist options
  • Save dedico/3070738 to your computer and use it in GitHub Desktop.
Save dedico/3070738 to your computer and use it in GitHub Desktop.
correct elasticsearch query
{
"query":{
"bool":{
"must":[
{
"match_all":{ }
},
{
"term":{
"vehicles.vehicle_category_id":{
"term":"1"
}
}
},
{
"term":{
"vehicles.make_id":{
"term":"71"
}
}
},
{
"term":{
"vehicles.model_id":{
"term":"1819"
}
}
}
]
}
},
"facets":{
"power":{
"terms":{
"field":"vehicles.power_km",
"size":1000,
"all_terms":true
}
},
"capacity":{
"terms":{
"field":"vehicles.engine_capacity",
"size":1000,
"all_terms":true
}
}
},
"filter":{
"and":[
{
"term":{
"vehicles.power_km":"105"
}
},
{
"term":{
"vehicles.engine_capacity":"1781"
}
}
]
},
"size":30,
"from":0
}
@dedico
Copy link
Author

dedico commented Jul 8, 2012

This query gives me reasonable results (exactly 12 results), the only problem is that I'd like to somehow make facet counts dependent on each other.
When I select one of the terms using 'power' facet I'd like to see filtered terms on 'capacity' facet according to selected 'power' term.
When I try to apply facet filter (https://gist.github.com/3070809) on 'capacity' facet, I get incorrect results - the query returns 29 results, which is as it would completely ignore filters.

Can anybody explain what is going on?
I'm using tire gem - here is the search action without facet filter:
https://gist.github.com/3070955
and here with the facet filter
https://gist.github.com/3070963

Thanks,
Marek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment