Search in sub attributes

Hi,

Suppose I have document like:

{
"email": {
"to": [
{
"name": {
"first_name": "Jonh",
"last_name": "Johnson"
}
},
{
"name": {
"first_name": "Mark",
"last_name": "Smith"
}
}
],
"message": "This is a tweet!"
}
}

I'm trying to search for mails to "John Smith". If I will just search like:
{
"bool": {
"must": [
{
"name.first_name": {
"user": "Jonh"
}
},
{
"name.second_name": {
"user": "Smith"
}
}
]
}
}

I'm getting document I've described - it have somebody with first name "John" as recipient and somebody whos second name is Smith. But it is not correct, because I want to get mails to "John Smith" really.

Very silly question, but I can't understand how to solve it

You'll need to use Nested documents or Parent/Child. Inner objects like
you have do not maintain relations between elements. The fields just
become bags of values:

{
"name.first_name" : ["John", "Mark"],
"name.last_name" : ["Johnson", "Smith",
}

Check out this article on document relations in elasticsearchhttp://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/,
it should clear up help understand how everything is working.

-Zach

On Friday, September 20, 2013 1:30:02 PM UTC-4, Alexey Sidelnikov wrote:

Hi,

Suppose I have document like:

{
"email": {
"to": [
{
"name": {
"first_name": "Jonh",
"last_name": "Johnson"
}
},
{
"name": {
"first_name": "Mark",
"last_name": "Smith"
}
}
],
"message": "This is a tweet!"
}
}

I'm trying to search for mails to "John Smith". If I will just search
like:
{
"bool": {
"must": [
{
"name.first_name": {
"user": "Jonh"
}
},
{
"name.second_name": {
"user": "Smith"
}
}
]
}
}

I'm getting document I've described - it have somebody with first name
"John" as recipient and somebody whos second name is Smith. But it is not
correct, because I want to get mails to "John Smith" really.

Very silly question, but I can't understand how to solve it

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Search-in-sub-attributes-tp4041622.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

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