# Query with an array of values

**URL:** <https://discuss.elastic.co/t/query-with-an-array-of-values/8908>\
**Category:** Elasticsearch\
**Created:** [August 31, 2012, 6:28pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908 "2012-08-31T18:28:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![banderon1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/banderon1/32/2689_2.png) [@banderon1](https://discuss.elastic.co/u/banderon1)\
**Post date:** [August 31, 2012, 6:28pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/1 "2012-08-31T18:28:30Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 31, 2012, 6:38pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/2 "2012-08-31T18:38:37Z")

</div>

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

Does it help?

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

Le 31 août 2012 à 20:28, banderon1 [banderon1@gmail.com](mailto: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...

--

---

<div class="post-metadata">

**Author:** ![banderon1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/banderon1/32/2689_2.png) [@banderon1](https://discuss.elastic.co/u/banderon1)\
**Post date:** [August 31, 2012, 6:47pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/3 "2012-08-31T18:47:34Z")

</div>

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 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 août 2012 à 20:28, banderon1 \<[band...@gmail.com](mailto: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...
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 31, 2012, 6:50pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/4 "2012-08-31T18:50:35Z")

</div>

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 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 août 2012 à 20:47, banderon1 [banderon1@gmail.com](mailto: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 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 août 2012 à 20:28, banderon1 [band...@gmail.com](mailto: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...
> 
> --

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 31, 2012, 6:53pm UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/5 "2012-08-31T18:53:11Z")

</div>

Look at this excellent post from Karel: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/2011/05/13/data-visualization-with-elasticsearch-and-protovis.html)

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

Le 31 août 2012 à 20:50, David Pilato [david@pilato.fr](mailto: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 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 août 2012 à 20:47, banderon1 [banderon1@gmail.com](mailto: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 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 31 août 2012 à 20:28, banderon1 [band...@gmail.com](mailto: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...
> > 
> > --
> 
> --

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:14am UTC](https://discuss.elastic.co/t/query-with-an-array-of-values/8908/6 "2017-07-06T03:14:23Z")

</div>


