I have a small document that looks like this
{country: int, state: int, city: int, studio: bool}
I build a facet for listing cities using the following query:
{"query":
{"bool":{"must":[
{"term":{"country":23424954}},
{"term":{"state":20070561}}]
}},"size":0,
"facets":{"role":{"terms":{"size":3,"field":"role"}},"studio":{"terms":
{"size":2,"field":"studio"}},"location_lights":{"terms":{"size":
2,"field":"on_location_lights"}},"country":{"terms":{"size":
300,"field":"country"}},"state":{"terms":{"size":
100,"field":"state"}},"city":{"terms":{"size":400,"field":"city"}}}}
I works as it should, it gives me the cities and the studio count. All
is good. The problem is that I want my users to be able to select
multiple cities and have the hits and studio count reflect the
choices. This is the query I have right now:
{"query":
{"bool":{
"must":[
{"term":{"country":23424954}}
,{"term":{"state":20070561}}],
"should":[
{"terms":{"city":[895018]}}]
}},"size":0,"facets":{"role":{"terms":{"size":
3,"field":"role"}},"studio":{"terms":{"size":
2,"field":"studio"}},"location_lights":{"terms":{"size":
2,"field":"on_location_lights"}},"country":{"terms":{"size":
300,"field":"country"}},"state":{"terms":{"size":
100,"field":"state"}},"city":{"terms":{"size":400,"field":"city"}}}}
It gets me as far as still showing all the cities (making multiple
choices an option), but the returning hits are wrong (size is 0 I
know, but if I increase it). Also, the studio field doesn't reflect
the choice of city/cities, but rather the state. Using "must" and
adding city there removes the other cities from the result which
remove multiple select as an option.
Is it possible to generate two facets, one that reflects the choice of
city and one that just lists the cities?
Right now the only thing I can think of is doing two queries, but that
will quickly get out of hand.
I'm very new to ES, which is probably kind of obvious