# Problem querying nested values with couchdb river

**URL:** <https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531>\
**Category:** Elasticsearch\
**Created:** [October 6, 2011, 4:12pm UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531 "2011-10-06T16:12:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cread](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cread/32/538_2.png) [@cread](https://discuss.elastic.co/u/cread)\
**Post date:** [October 6, 2011, 4:12pm UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531/1 "2011-10-06T16:12:41Z")

</div>

Greetings...

I'm pretty new to elasticsearch, and I'm having trouble with searching  
nested items in a couchdb document. I'm trying to find out what I'm  
doing wrong.

Given the following document on couch:

-- %\< --  
{  
"name": "phrydde",  
"hands": {  
"left": {  
"color": "blue"  
},  
"right": {  
"color": "green"  
}  
}  
-- %\< --

When I run the following query, I get the answer "phrydde" as  
expected:

-- %\< query --  
{  
query: {  
bool: {  
must: [  
{  
query\_string: {  
default\_field: color,  
query: blue  
}  
}  
]  
}  
},  
fields: name  
}  
-- %\< query --

but when I run this query:

-- %\< query --  
{  
query: {  
bool: {  
must: [  
{  
query\_string: {  
default\_field: color,  
query: green  
}  
}  
]  
}  
},  
fields: name  
}  
-- %\< query --

I don't get any matches.

I'm using couchdb 1.1.0 and elasticsearch 0.17.6

Thanks in advance...

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:** [October 6, 2011, 7:06pm UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531/2 "2011-10-06T19:06:38Z")

</div>

You need to specify the full path to the field you want to query, for  
example: hands.left.color, or hands.right.color. If you just specify color,  
elasticsearch will pick one of those and query it (it would be nice if it  
would automatically "expand" the query into one across all the color fields,  
but its not there...).

Also, is "hands" an array of objects, or a single object?

On Thu, Oct 6, 2011 at 6:12 PM, Chris Read [chris.read@gmail.com](mailto:chris.read@gmail.com) wrote:

> Greetings...
> 
> I'm pretty new to elasticsearch, and I'm having trouble with searching  
> nested items in a couchdb document. I'm trying to find out what I'm  
> doing wrong.
> 
> Given the following document on couch:
> 
> -- %\< --  
> {  
> "name": "phrydde",  
> "hands": {  
> "left": {  
> "color": "blue"  
> },  
> "right": {  
> "color": "green"  
> }  
> }  
> -- %\< --
> 
> When I run the following query, I get the answer "phrydde" as  
> expected:
> 
> -- %\< query --  
> {  
> query: {  
> bool: {  
> must: [  
> {  
> query\_string: {  
> default\_field: color,  
> query: blue  
> }  
> }  
> ]  
> }  
> },  
> fields: name  
> }  
> -- %\< query --
> 
> but when I run this query:
> 
> -- %\< query --  
> {  
> query: {  
> bool: {  
> must: [  
> {  
> query\_string: {  
> default\_field: color,  
> query: green  
> }  
> }  
> ]  
> }  
> },  
> fields: name  
> }  
> -- %\< query --
> 
> I don't get any matches.
> 
> I'm using couchdb 1.1.0 and elasticsearch 0.17.6
> 
> Thanks in advance...
> 
> Chris

---

<div class="post-metadata">

**Author:** ![cread](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cread/32/538_2.png) [@cread](https://discuss.elastic.co/u/cread)\
**Post date:** [October 7, 2011, 8:29am UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531/3 "2011-10-07T08:29:50Z")

</div>

At the moment hands is a single object. Would it make a difference if  
it was an array?

On Oct 6, 8:06 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You need to specify the full path to the field you want to query, for  
> example: hands.left.color, or hands.right.color. If you just specify color,  
> elasticsearch will pick one of those and query it (it would be nice if it  
> would automatically "expand" the query into one across all the color fields,  
> but its not there...).
> 
> Also, is "hands" an array of objects, or a single object?
> 
> On Thu, Oct 6, 2011 at 6:12 PM, Chris Read [chris.r...@gmail.com](mailto:chris.r...@gmail.com) wrote:
> 
> > Greetings...
> 
> > I'm pretty new to elasticsearch, and I'm having trouble with searching  
> > nested items in a couchdb document. I'm trying to find out what I'm  
> > doing wrong.
> 
> > Given the following document on couch:
> 
> > -- %\< --  
> > {  
> > "name": "phrydde",  
> > "hands": {  
> > "left": {  
> > "color": "blue"  
> > },  
> > "right": {  
> > "color": "green"  
> > }  
> > }  
> > -- %\< --
> 
> > When I run the following query, I get the answer "phrydde" as  
> > expected:
> 
> > -- %\< query --  
> > {  
> > query: {  
> > bool: {  
> > must: [  
> > {  
> > query\_string: {  
> > default\_field: color,  
> > query: blue  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > fields: name  
> > }  
> > -- %\< query --
> 
> > but when I run this query:
> 
> > -- %\< query --  
> > {  
> > query: {  
> > bool: {  
> > must: [  
> > {  
> > query\_string: {  
> > default\_field: color,  
> > query: green  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > fields: name  
> > }  
> > -- %\< query --
> 
> > I don't get any matches.
> 
> > I'm using couchdb 1.1.0 and elasticsearch 0.17.6
> 
> > Thanks in advance...
> 
> > 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:** [October 8, 2011, 6:50pm UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531/4 "2011-10-08T18:50:26Z")

</div>

If it is an array, then a common confusion is trying to find docs with  
hands.left.color:green AND hands.right.color:blue, and expecting that only  
an array _element_ that contains both will return a hit. This is not the  
case (by default), and it will return a result without regards to the array  
elements.

If you would want to have array elements level query, you would need to use  
nested mapping for hands, and use nested queries / filters to query hands.

On Fri, Oct 7, 2011 at 10:29 AM, Chris Read [chris.read@gmail.com](mailto:chris.read@gmail.com) wrote:

> At the moment hands is a single object. Would it make a difference if  
> it was an array?
> 
> On Oct 6, 8:06 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > You need to specify the full path to the field you want to query, for  
> > example: hands.left.color, or hands.right.color. If you just specify  
> > color,  
> > elasticsearch will pick one of those and query it (it would be nice if it  
> > would automatically "expand" the query into one across all the color  
> > fields,  
> > but its not there...).
> > 
> > Also, is "hands" an array of objects, or a single object?
> > 
> > On Thu, Oct 6, 2011 at 6:12 PM, Chris Read [chris.r...@gmail.com](mailto:chris.r...@gmail.com) wrote:
> > 
> > > Greetings...
> > 
> > > I'm pretty new to elasticsearch, and I'm having trouble with searching  
> > > nested items in a couchdb document. I'm trying to find out what I'm  
> > > doing wrong.
> > 
> > > Given the following document on couch:
> > 
> > > -- %\< --  
> > > {  
> > > "name": "phrydde",  
> > > "hands": {  
> > > "left": {  
> > > "color": "blue"  
> > > },  
> > > "right": {  
> > > "color": "green"  
> > > }  
> > > }  
> > > -- %\< --
> > 
> > > When I run the following query, I get the answer "phrydde" as  
> > > expected:
> > 
> > > -- %\< query --  
> > > {  
> > > query: {  
> > > bool: {  
> > > must: [  
> > > {  
> > > query\_string: {  
> > > default\_field: color,  
> > > query: blue  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > },  
> > > fields: name  
> > > }  
> > > -- %\< query --
> > 
> > > but when I run this query:
> > 
> > > -- %\< query --  
> > > {  
> > > query: {  
> > > bool: {  
> > > must: [  
> > > {  
> > > query\_string: {  
> > > default\_field: color,  
> > > query: green  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > },  
> > > fields: name  
> > > }  
> > > -- %\< query --
> > 
> > > I don't get any matches.
> > 
> > > I'm using couchdb 1.1.0 and elasticsearch 0.17.6
> > 
> > > Thanks in advance...
> > 
> > > Chris

---

<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:52am UTC](https://discuss.elastic.co/t/problem-querying-nested-values-with-couchdb-river/5531/5 "2017-07-06T03:52:32Z")

</div>


