# Search on the nth element in an array

**URL:** <https://discuss.elastic.co/t/search-on-the-nth-element-in-an-array/14008>\
**Category:** Elasticsearch\
**Created:** [October 18, 2013, 9:12am UTC](https://discuss.elastic.co/t/search-on-the-nth-element-in-an-array/14008 "2013-10-18T09:12:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [October 18, 2013, 9:12am UTC](https://discuss.elastic.co/t/search-on-the-nth-element-in-an-array/14008/1 "2013-10-18T09:12:29Z")

</div>

If I have an array in my index

{  
"myArray":{  
{  
myValue:50  
},  
{  
myValue:160  
}  
}  
}

Is there a way to search on objects in the array by specifying the array  
index value, in the example below I want to search on the first element in  
the array

{  
"query": {  
"query\_string":{"query":"myArray[0].myValue:50"}  
}  
}

The query above gives me a parse error.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [October 18, 2013, 9:49am UTC](https://discuss.elastic.co/t/search-on-the-nth-element-in-an-array/14008/2 "2013-10-18T09:49:59Z")

</div>

If the position is important then I would recommend making an object field  
from it. Thus it will be indexed and used for search in efficient way.

Regards,  
Lukáš  
Dne 18.10.2013 11:12 "dan" [dan.tuffery@gmail.com](mailto:dan.tuffery@gmail.com) napsal(a):

> If I have an array in my index
> 
> {  
> "myArray":{  
> {  
> myValue:50  
> },  
> {  
> myValue:160  
> }  
> }  
> }
> 
> Is there a way to search on objects in the array by specifying the array  
> index value, in the example below I want to search on the first element in  
> the array
> 
> {  
> "query": {  
> "query\_string":{"query":"myArray[0].myValue:50"}  
> }  
> }
> 
> The query above gives me a parse error.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:11am UTC](https://discuss.elastic.co/t/search-on-the-nth-element-in-an-array/14008/3 "2017-07-06T02:11:46Z")

</div>


