# Bool query on nested objects

**URL:** <https://discuss.elastic.co/t/bool-query-on-nested-objects/3756>\
**Category:** Elasticsearch\
**Created:** [January 9, 2011, 8:43am UTC](https://discuss.elastic.co/t/bool-query-on-nested-objects/3756 "2011-01-09T08:43:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lowang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lowang/32/3284_2.png) [@lowang](https://discuss.elastic.co/u/lowang)\
**Post date:** [January 9, 2011, 8:43am UTC](https://discuss.elastic.co/t/bool-query-on-nested-objects/3756/1 "2011-01-09T08:43:51Z")

</div>

hi,

I've following document structure:

curl -XPUT [http://localhost:9200/lowang/product/1](http://localhost:9200/lowang/product/1) -d '  
{  
"\_id":1,  
"title":"T-shirt",  
"offers": [  
{  
"price": 10,  
"properties":[{"color":"red"}]  
},  
{  
"price": 12,  
"properties":[{"color":"black"}]  
}  
]  
}'

and I want to find products that are red t-shirts priced at 12 - in  
above example such product doesn't exist.  
I ended with following query:

curl -XGET '[http://ds3:9200/lowang/product/\_search?pretty=true](http://ds3:9200/lowang/product/_search?pretty=true)' -d '{  
"query": {  
"bool" : {  
"must" : [  
{  
"query\_string" : {  
"query" : "offers.properties.color = red"  
}  
},  
{  
"query\_string" : {  
"query" : "offers.price = 12"  
}  
}  
]  
}  
}  
}'

however it's returning result, while I was expecting it to fail. What  
I really need to do is to have AND operator working on single offer,  
how can I accomplish that ?

---

<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:** [January 11, 2011, 10:24pm UTC](https://discuss.elastic.co/t/bool-query-on-nested-objects/3756/2 "2011-01-11T22:24:25Z")

</div>

This is because there is no concept of "compound" structure in the document created. So it matches on both. The parent child feature supports that, but it still missing some features to get what you want (like getting the children back).  
On Sunday, January 9, 2011 at 10:43 AM, Przemyslaw Wroblewski wrote:

> hi,
> 
> I've following document structure:
> 
> curl -XPUT [http://localhost:9200/lowang/product/1](http://localhost:9200/lowang/product/1) -d '  
> {  
> "\_id":1,  
> "title":"T-shirt",  
> "offers": [  
> {  
> "price": 10,  
> "properties":[{"color":"red"}]  
> },  
> {  
> "price": 12,  
> "properties":[{"color":"black"}]  
> }  
> ]  
> }'
> 
> and I want to find products that are red t-shirts priced at 12 - in  
> above example such product doesn't exist.  
> I ended with following query:
> 
> curl -XGET '[http://ds3:9200/lowang/product/\_search?pretty=true](http://ds3:9200/lowang/product/_search?pretty=true)' -d '{  
> "query": {  
> "bool" : {  
> "must" : [  
> {  
> "query\_string" : {  
> "query" : "offers.properties.color = red"  
> }  
> },  
> {  
> "query\_string" : {  
> "query" : "offers.price = 12"  
> }  
> }  
> ]  
> }  
> }  
> }'
> 
> however it's returning result, while I was expecting it to fail. What  
> I really need to do is to have AND operator working on single offer,  
> how can I accomplish that ?

---

<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, 4:14am UTC](https://discuss.elastic.co/t/bool-query-on-nested-objects/3756/3 "2017-07-06T04:14:01Z")

</div>


