# Query based on array values

**URL:** https://discuss.elastic.co/t/query-based-on-array-values/10016
**Category:** Elasticsearch
**Created:** [December 10, 2012, 12:52pm UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016 "2012-12-10T12:52:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://discuss.elastic.co/u/karan)
#### Post date: [December 10, 2012, 12:52pm UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016/1 "2012-12-10T12:52:21Z")

</div>

Hi,

Needed some help.  
I need to query documents based on the inner values of an array.  
{id:1 , version:[1],…}  
{id:1 , version:[2],….}  
{id:2 , version:[1,2],…}

I needed to do faceted search and also query based on version value.  
Example if i query for version 1, i should get:  
{id:1 , version:[1],…}  
{id:2 , version:[1,2],…}

Example if i query for version 2, i should get:  
{id:1 , version:[2],….}  
{id:2 , version:[1,2],…}

please help,  
Karan

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [December 10, 2012, 6:38pm UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016/2 "2012-12-10T18:38:38Z")

</div>

You can just query on an array field as you would do for a normal field.  
Take a look at the match query:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Martijn

On 10 December 2012 13:52, karan [jaskaran1981@gmail.com](mailto:jaskaran1981@gmail.com) wrote:

> Hi,
> 
> Needed some help.  
> I need to query documents based on the inner values of an array.  
> {id:1 , version:[1],…}  
> {id:1 , version:[2],….}  
> {id:2 , version:[1,2],…}
> 
> I needed to do faceted search and also query based on version value.  
> Example if i query for version 1, i should get:  
> {id:1 , version:[1],…}  
> {id:2 , version:[1,2],…}
> 
> Example if i query for version 2, i should get:  
> {id:1 , version:[2],….}  
> {id:2 , version:[1,2],…}
> 
> please help,  
> Karan
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Query-based-on-array-values-tp4026757.html](http://elasticsearch-users.115913.n3.nabble.com/Query-based-on-array-values-tp4026757.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --

--  
Met vriendelijke groet,

Martijn van Groningen

--

---

<div class="post-metadata">

### Author: ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://discuss.elastic.co/u/karan)
#### Post date: [December 12, 2012, 8:29am UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016/3 "2012-12-12T08:29:21Z")

</div>

Hi Martijn,

Thanks alot ...this worked for me.

Thanks,  
Karan

On Tuesday, December 11, 2012 12:08:38 AM UTC+5:30, Martijn v Groningen  
wrote:

> You can just query on an array field as you would do for a normal field.  
> Take a look at the match query:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html)
> 
> Martijn
> 
> On 10 December 2012 13:52, karan \<[jaskar...@gmail.com](mailto:jaskar...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Hi,
> > 
> > Needed some help.  
> > I need to query documents based on the inner values of an array.  
> > {id:1 , version:[1],…}  
> > {id:1 , version:[2],….}  
> > {id:2 , version:[1,2],…}
> > 
> > I needed to do faceted search and also query based on version value.  
> > Example if i query for version 1, i should get:  
> > {id:1 , version:[1],…}  
> > {id:2 , version:[1,2],…}
> > 
> > Example if i query for version 2, i should get:  
> > {id:1 , version:[2],….}  
> > {id:2 , version:[1,2],…}
> > 
> > please help,  
> > Karan
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Query-based-on-array-values-tp4026757.html](http://elasticsearch-users.115913.n3.nabble.com/Query-based-on-array-values-tp4026757.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> > 
> > --
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

--

---

<div class="post-metadata">

### Author: ![amargarg](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@amargarg](https://discuss.elastic.co/u/amargarg)
#### Post date: [July 5, 2013, 9:58am UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016/4 "2013-07-05T09:58:38Z")

</div>

Hi,  
I have documents in a collection as per following structure.  
Document 1 = { "A":[  
{  
"type": "1",  
"method": "auto",  
"value": "some data"  
},  
{  
"type": "2",  
"method": "auto",  
"value": "some data"  
},  
{  
"type": "3",  
"method": "auto",  
"value": "some data"  
}],  
...  
...  
}

Document 2 = { "A":[  
{  
"type": "1",  
"method": "manual",  
"value": "some data"  
},  
{  
"type": "2",  
"method": "auto",  
"value": "some data"  
},  
{  
"type": "3",  
"method": "manual",  
"value": "some data"  
}],  
...  
...  
}

Document 3 = { "A":[  
{  
"type": "1",  
"method": "manual",  
"value": "some data"  
},  
{  
"type": "2",  
"method": "manual",  
"value": "some data"  
},  
{  
"type": "3",  
"method": "auto",  
"value": "some data"  
}],  
...  
...  
}

On these documents, I want to query two fields in array A..  
Example 1: if I query "A.type":"1" AND "A.method":"manual", I should get document 2 and document 3 in return.  
Example 2: if I query "A.type":"2" AND "A.method":"auto", I should get document 1 and document 2 in return.  
Example 3: if I query "A.type":"2" AND "A.method":"manual", I should get only document 3 in return.

Is there a way to achieve this in ElasticSearch?

---

<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, 2:28am UTC](https://discuss.elastic.co/t/query-based-on-array-values/10016/5 "2017-07-06T02:28:04Z")

</div>


