# Querying for records not containing specified nested element

**URL:** <https://discuss.elastic.co/t/querying-for-records-not-containing-specified-nested-element/23756>\
**Category:** Elasticsearch\
**Created:** [June 9, 2015, 9:39am UTC](https://discuss.elastic.co/t/querying-for-records-not-containing-specified-nested-element/23756 "2015-06-09T09:39:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nishant](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@Nishant](https://discuss.elastic.co/u/Nishant)\
**Post date:** [June 9, 2015, 9:39am UTC](https://discuss.elastic.co/t/querying-for-records-not-containing-specified-nested-element/23756/1 "2015-06-09T09:39:34Z")

</div>

Hi,  
I am new to elasticsearch and trying to evaluate its usability for my project. My documents will be mapped as follows:  
{  
"sales": {  
"properties" :  
{  
"id" : {  
"type" : "long"  
},  
......  
"outlets" : {  
"type" : "nested",  
"properties" : {  
"name" : {  
"type" : "string","index":"not\_analyzed"  
},  
"branchId" : {  
"type" : "long"  
}  
"products" : {  
"type" : "nested",  
"properties" : {  
"code" : {  
"type" : "string","index":"not\_analyzed"  
},  
"inventory" : {  
"type" : "integer"  
},  
"price" : {  
"type" : "double"  
}  
}  
}  
}  
}  
}  
}  
}

I require to find the name of the outlets which do not sell a particular code. I have tried using "not" & "must\_not" filters. However if an outlet 'X' contains 2 product codes, say 'a' and 'b' and I query with not or must\_not filters with a match query for 'a', I still get X as it has another nested element 'b' which satisfies the match criteria.

I have also tried mapping the records to 3 sets of documents related as parent and child. However the inner hits in both the cases do not seem to work.

---

<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, 12:08am UTC](https://discuss.elastic.co/t/querying-for-records-not-containing-specified-nested-element/23756/2 "2017-07-06T00:08:54Z")

</div>


