Problem querying nested values with couchdb river

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

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 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

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 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 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

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 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 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 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