Query on multiple nested objects

a have Author model

Author: {
name: xyz,
books: [ { //nested object
title: "abc",
date: 1/1/1
},{
title: "123"
date: 2/2/2
}
],
deals: [{ //nested object
name: "best",
deal_end_at: 1/1/15
},
{
name: "not so good",
deal_end_at: 1/2/13
}

]
}

is it possible to construct a single query to find the author where
"author.book.title = 'abc'" and "deals.name = 'best' "?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Yes, this is possible by using a match query for your title query and a
nested query that wraps a match query for the deal names. Both the nested
and match query need to combined with a bool query. Example:
curl -XGET 'localhost:9200/_search' -d '
"query" : {
"bool" : {
"must" : [
{
"match" : {
"name" : {
"abc"
}
}
},
"nested" : {
"path" : "deals",
"query" : {
"match" : {
"name" : {
"best"
}
}
}
}
]
}
}
'

On 3 April 2013 01:37, Victor vicwin@gmail.com wrote:

a have Author model

Author: {
name: xyz,
books: [ { //nested object
title: "abc",
date: 1/1/1
},{
title: "123"
date: 2/2/2
}
],
deals: [{ //nested object
name: "best",
deal_end_at: 1/1/15
},
{
name: "not so good",
deal_end_at: 1/2/13
}

]
}

is it possible to construct a single query to find the author where
"author.book.title = 'abc'" and "deals.name = 'best' "?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

in the first match query, how does ES knows "name" mapped to
"books.title"? am i missing something

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ES doesn't know that. I misread your question / example. The book.title
part should also be put into a nested query:
curl -XGET 'localhost:9200/_search' -d '
"query" : {
"bool" : {
"must" : [
{
"nested" : {
"path" : "books",
"query" : {
"match" : {
"books.title" : {
"abc"
}
}
}
}
},
"nested" : {
"path" : "deals",
"query" : {
"match" : {
"deals.name" : {
"best"
}
}
}
}
]
}
}
'

Also the field names inside the nested query should be the full path. The
above query should return any root document (author in your case) that has
a nested inner deal object with a name that has the term best and a
nested inner book object with title that has a term abc. Does this makes
sense?

On 3 April 2013 19:16, Victor Huang vicwin@gmail.com wrote:

in the first match query, how does ES knows "name" mapped to
"books.title"? am i missing something

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Met vriendelijke groet,

Martijn van Groningen

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.