# Elastic SQL - exclude documents based on nested objects

**URL:** <https://discuss.elastic.co/t/elastic-sql-exclude-documents-based-on-nested-objects/356272>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [March 27, 2024, 11:19am UTC](https://discuss.elastic.co/t/elastic-sql-exclude-documents-based-on-nested-objects/356272 "2024-03-27T11:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elichai](https://avatars.discourse-cdn.com/v4/letter/e/7feea3/32.png) [@elichai](https://discuss.elastic.co/u/elichai)\
**Post date:** [March 27, 2024, 11:19am UTC](https://discuss.elastic.co/t/elastic-sql-exclude-documents-based-on-nested-objects/356272/1 "2024-03-27T11:19:42Z")

</div>

Hi,  
I need to filter out documents that meet a condition in one of its nested objects. For example, if there is at least one nested object that has a code of 708 the document should not match. However, when I specify "AND nested.code \<\> 708", as long as there is one nested object without code 708 the document will be matched.  
In JSON search this will be in the must\_not query (filtering out documents which contain nested objects with code 708)  
In RDBMS this would be accomplished with a sub query or outer apply.  
Is there a way to do this in ES SQL ?

Thanks

---

<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:** [April 24, 2024, 11:20am UTC](https://discuss.elastic.co/t/elastic-sql-exclude-documents-based-on-nested-objects/356272/2 "2024-04-24T11:20:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
