Query with an array of values


(banderon1) #1

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...

--


(David Pilato) #2

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...

--


(banderon1) #3

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...

--

--


(David Pilato) #4

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...

--

--


(David Pilato) #5

Look at this excellent post from Karel: http://www.elasticsearch.org/blog/2011/05/13/data-visualization-with-elasticsearch-and-protovis.html

--
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...

--

--

--


(system) #6