# Create query where nested array elements must be in provided set

**URL:** <https://discuss.elastic.co/t/create-query-where-nested-array-elements-must-be-in-provided-set/61734>\
**Category:** Elasticsearch\
**Created:** [September 28, 2016, 7:17pm UTC](https://discuss.elastic.co/t/create-query-where-nested-array-elements-must-be-in-provided-set/61734 "2016-09-28T19:17:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Bourne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_bourne/32/53053_2.png) [@Kevin\_Bourne](https://discuss.elastic.co/u/Kevin_Bourne)\
**Post date:** [September 28, 2016, 7:17pm UTC](https://discuss.elastic.co/t/create-query-where-nested-array-elements-must-be-in-provided-set/61734/1 "2016-09-28T19:17:37Z")

</div>

Say I have a nested array of values in a document. Is there a way to specify that all the elements in the array of values must be in a provided list of values?

For example I have two documents:

{  
...  
"key" : [ {  
"innerKey" : "something"  
} , {  
"innerKey" : "another"  
} , {  
"innerKey" : "whatsit"  
}  
]  
...  
}, {  
...  
"key" : [ {  
"innerKey" : "something"  
} , {  
"innerKey" : "different"  
}]  
...  
}

I want to create a query where I give a list of values and returned are the documents where all the "innerKey" values exist in the provided list.

Back to the documents above, I want to pass in a list of values such as ["something", "anything", "different", "anyOtherValue"] and return only the 2nd document since all of its element exists in this list.

Is there a way to do this in a DSL query? Note that I actually want to do this in Java using combination of Jest and ES Java API so I could perform this logic after I get the results back, but I would like to have ES handle it if possible.

---

<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 5, 2017, 10:16pm UTC](https://discuss.elastic.co/t/create-query-where-nested-array-elements-must-be-in-provided-set/61734/2 "2017-07-05T22:16:30Z")

</div>


