Multiple select with facets

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 :slight_smile:

Two things:

  1. Facets can be configured to run globally (not bounded by the search query), and then associate a filter with them.
  2. Facets can have an extra filter on them to further reduce the docs they will be executed on.

Both allows you to control the relevant docs the facets will be executed on.
On Sunday, January 9, 2011 at 3:25 PM, Erik J wrote:

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 :slight_smile:

Aha!

With a combination of a global scan and then by dynamically populating
the facet filter for city depending on other choices I get a multiple
choice facet with reflected results over the other properties.

Thanks for the pointers, everything is working as intended now :slight_smile:

On Jan 11, 11:26 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Two things:

  1. Facets can be configured to run globally (not bounded by the search query), and then associate a filter with them.
  2. Facets can have an extra filter on them to further reduce the docs they will be executed on.

Both allows you to control the relevant docs the facets will be executed on.

On Sunday, January 9, 2011 at 3:25 PM, Erik J wrote:

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 :slight_smile:

Shay, would the scope variable (e.g of RangeFacet) help me here, like
I mentioned in this issue:

Regards,
Peter.

On 12 Jan., 00:54, Erik J erikjohansson....@gmail.com wrote:

Aha!

With a combination of a global scan and then by dynamically populating
the facet filter for city depending on other choices I get a multiple
choice facet with reflected results over the other properties.

Thanks for the pointers, everything is working as intended now :slight_smile:

On Jan 11, 11:26 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Two things:

  1. Facets can be configured to run globally (not bounded by the search query), and then associate a filter with them.
  2. Facets can have an extra filter on them to further reduce the docs they will be executed on.

Both allows you to control the relevant docs the facets will be executed on.

On Sunday, January 9, 2011 at 3:25 PM, Erik J wrote:

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 :slight_smile:

The scope allows you to control if its executed globally or not. I just pushed a feature that might help with that: Search: Allow to pass a search filter, applying only on the query (and not on facets for example) · Issue #650 · elastic/elasticsearch · GitHub. Ping if it does...

-shay.banon
On Monday, January 24, 2011 at 4:42 PM, Karussell wrote:

Shay, would the scope variable (e.g of RangeFacet) help me here, like
I mentioned in this issue:

Multi-select facets · Issue #499 · elastic/elasticsearch · GitHub

Regards,
Peter.

On 12 Jan., 00:54, Erik J erikjohansson....@gmail.com wrote:

Aha!

With a combination of a global scan and then by dynamically populating
the facet filter for city depending on other choices I get a multiple
choice facet with reflected results over the other properties.

Thanks for the pointers, everything is working as intended now :slight_smile:

On Jan 11, 11:26 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Two things:

  1. Facets can be configured to run globally (not bounded by the search query), and then associate a filter with them.
  2. Facets can have an extra filter on them to further reduce the docs they will be executed on.

Both allows you to control the relevant docs the facets will be executed on.

On Sunday, January 9, 2011 at 3:25 PM, Erik J wrote:

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 :slight_smile: