Query with an array of values

I have an elasticsearch index with numeric category ids like this:

{"id":"50958","name":"product name","description":"product
description","upc":"00302590602108","categories
":["26","39"],"price":"15.95"}

I want to be able to pass an array of category ids (a parent id with all of
it's children, for example) and return only results that match one of those
categories. I have been trying to get it to work with a term query, but no
luck yet.

Also, as a new user of elasticsearch, I am wondering if I should use a
filter/facet for this...

--

I think I will use a bool Query with 2 must TermQuery on categories field, one for each value.

Does it help?

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

Le 31 août 2012 à 20:28, banderon1 banderon1@gmail.com a écrit :

I have an elasticsearch index with numeric category ids like this:

{"id":"50958","name":"product name","description":"product description","upc":"00302590602108","categories":["26","39"],"price":"15.95"}

I want to be able to pass an array of category ids (a parent id with all of it's children, for example) and return only results that match one of those categories. I have been trying to get it to work with a term query, but no luck yet.

Also, as a new user of elasticsearch, I am wondering if I should use a filter/facet for this...

--

I ended up using a terms query (as opposed to term). I'm still interested
in knowing if there would be a benefit to using a filter or facet.

On Friday, August 31, 2012 11:38:49 AM UTC-7, David Pilato wrote:

I think I will use a bool Query with 2 must TermQuery on categories field,
one for each value.

Does it help?

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

Le 31 août 2012 à 20:28, banderon1 <band...@gmail.com <javascript:>> a
écrit :

I have an elasticsearch index with numeric category ids like this:

{"id":"50958","name":"product name","description":"product
description","upc":"00302590602108","categories
":["26","39"],"price":"15.95"}

I want to be able to pass an array of category ids (a parent id with all
of it's children, for example) and return only results that match one of
those categories. I have been trying to get it to work with a term query,
but no luck yet.

Also, as a new user of elasticsearch, I am wondering if I should use a
filter/facet for this...

--

--

A filter : definitly. Faster than query.
For facets, it's not the same use case.

Facets helps to get statistics on your docs, not for querying.

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

Le 31 août 2012 à 20:47, banderon1 banderon1@gmail.com a écrit :

I ended up using a terms query (as opposed to term). I'm still interested in knowing if there would be a benefit to using a filter or facet.

On Friday, August 31, 2012 11:38:49 AM UTC-7, David Pilato wrote:
I think I will use a bool Query with 2 must TermQuery on categories field, one for each value.

Does it help?

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

Le 31 août 2012 à 20:28, banderon1 band...@gmail.com a écrit :

I have an elasticsearch index with numeric category ids like this:

{"id":"50958","name":"product name","description":"product description","upc":"00302590602108","categories":["26","39"],"price":"15.95"}

I want to be able to pass an array of category ids (a parent id with all of it's children, for example) and return only results that match one of those categories. I have been trying to get it to work with a term query, but no luck yet.

Also, as a new user of elasticsearch, I am wondering if I should use a filter/facet for this...

--

--

Look at this excellent post from Karel: Elasticsearch Platform — Find real-time answers at scale | Elastic

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

Le 31 août 2012 à 20:50, David Pilato david@pilato.fr a écrit :

A filter : definitly. Faster than query.
For facets, it's not the same use case.

Facets helps to get statistics on your docs, not for querying.

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

Le 31 août 2012 à 20:47, banderon1 banderon1@gmail.com a écrit :

I ended up using a terms query (as opposed to term). I'm still interested in knowing if there would be a benefit to using a filter or facet.

On Friday, August 31, 2012 11:38:49 AM UTC-7, David Pilato wrote:
I think I will use a bool Query with 2 must TermQuery on categories field, one for each value.

Does it help?

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

Le 31 août 2012 à 20:28, banderon1 band...@gmail.com a écrit :

I have an elasticsearch index with numeric category ids like this:

{"id":"50958","name":"product name","description":"product description","upc":"00302590602108","categories":["26","39"],"price":"15.95"}

I want to be able to pass an array of category ids (a parent id with all of it's children, for example) and return only results that match one of those categories. I have been trying to get it to work with a term query, but no luck yet.

Also, as a new user of elasticsearch, I am wondering if I should use a filter/facet for this...

--

--

--