# Possible to use boolean on both nested and container doc fields?

**URL:** <https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096>\
**Category:** Elasticsearch\
**Created:** [December 8, 2011, 3:37am UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096 "2011-12-08T03:37:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schnyder](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Schnyder](https://discuss.elastic.co/u/Schnyder)\
**Post date:** [December 8, 2011, 3:37am UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096/1 "2011-12-08T03:37:04Z")

</div>

Is it possible to perform a boolean filter on fields in a nested document as well as its container document? Can I use \_parent in that situation?

I've been trying something similar to the following with no luck. If I only check the nested doc's properties, it is successful, however.

"nested": {  
"path": "nestedObj",  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"should" : [  
{"term" : {"fieldname" : "value1"}},  
{"term" : {"\_parent.fieldname" : "value2"}}  
]  
}  
}  
}

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 9, 2011, 10:23pm UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096/2 "2011-12-09T22:23:11Z")

</div>

You can't do a filter on a "parent" within a nested element, but, you can  
combine a non nested filter and a nested one (or query).

On Thu, Dec 8, 2011 at 5:37 AM, Schnyder \<  
[chris.schnyder@cardinal-holdings.com](mailto:chris.schnyder@cardinal-holdings.com)\> wrote:

> Is it possible to perform a boolean filter on fields in a nested document  
> as  
> well as its container document? Can I use \_parent in that situation?
> 
> I've been trying something similar to the following with no luck. If I  
> only  
> check the nested doc's properties, it is successful, however.
> 
> "nested": {  
> "path": "nestedObj",  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "bool": {  
> "should" : [  
> {"term" : {"fieldname" : "value1"}},  
> {"term" : {"\_parent.fieldname" : "value2"}}  
> ]  
> }  
> }  
> }
> 
> Thanks,  
> Chris
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Possible-to-use-boolean-on-both-nested-and-container-doc-fields-tp3569323p3569323.html](http://elasticsearch-users.115913.n3.nabble.com/Possible-to-use-boolean-on-both-nested-and-container-doc-fields-tp3569323p3569323.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Schnyder\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/schnyder_2/32/3046_2.png) [@Schnyder\_2](https://discuss.elastic.co/u/Schnyder_2)\
**Post date:** [December 10, 2011, 12:01am UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096/3 "2011-12-10T00:01:10Z")

</div>

Thanks Shay, but I need to do an "or" operation on these two fields (one  
field from the parent, and one field from the nested child). I don't think  
your solution would allow that, if I understand you correctly.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 10, 2011, 4:30pm UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096/4 "2011-12-10T16:30:28Z")

</div>

You can do an or between a nested query on that nested field, and a parent  
query on that parent field, no?

On Sat, Dec 10, 2011 at 2:01 AM, Schnyder [chris.schnyder@gmail.com](mailto:chris.schnyder@gmail.com) wrote:

> Thanks Shay, but I need to do an "or" operation on these two fields (one  
> field from the parent, and one field from the nested child). I don't think  
> your solution would allow that, if I understand you correctly.

---

<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, 3:45am UTC](https://discuss.elastic.co/t/possible-to-use-boolean-on-both-nested-and-container-doc-fields/6096/5 "2017-07-06T03:45:47Z")

</div>


