Highlight fragments in a collection fields- any way to see which item caused the match?

If I have a document with a collection field, and I have highlight
results on an item in such a collection, is there any way to identify
which item the match was on?

Here's an example:

curl -XDELETE 'http://127.0.0.1:9200/someindex?pretty=1'
curl -XPOST 'http://127.0.0.1:9200/someindex/user?pretty=1' -d '
{
"friends" : [
{
"name" : {
"first" : "Jack",
"last" : "Smith"
},
"email" : ["jack.smith@example.com",
"j.smith@example.com", "jack@smith.com", "jack@jacksmith.com"]
},
{
"name" : {
"first" : "Alice",
"last" : "Smith"
},
"email" : ["alice@example.com", "alice.smith@example.com"]
},
{
"name" : {
"first" : "Jack",
"last" : "Brown"
},
"email" : ["jb@example.com", "jack.brown@example.com",
"jack@example.com"]
}
]
}
'
curl -XGET 'http://127.0.0.1:9200/someindex/user/_search?pretty=1' -d
'
{
"query" : {
"query_string" : {
"query" : "jack",
"fields" : ["friends.name.first", "friends.name.last",
"friends.email"]
}
},
"highlight" : {
"fields" : {
"friends.name.first" : {},
"friends.name.last" : {},
"friends.email" : {}
}
}
}
'

Executing that search gets back a hit with the following highlight
info:

"highlight" : {
"friends.email" : [ "jack@smith.com", "jack</
em>@jacksmith.com", "jack@example.com" ],
"friends.name.first" : [ "Jack", "Jack" ]
}

Is there some way to determine which friend object each hit came off
of? I'm used to a Spring nested path syntax such as
"friends[0].name.first" or "friends[2].email[1]" or the like, but as
far as I can tell there is nothing similar in ES. On a hit on
something like "friends.name.first", I'd like to be able to provide
the broader context (both first and last name of the friend that
matched), but without knowing which friend object had the match, it is
difficult to put that together.

No, there isn't...
On Tuesday, May 17, 2011 at 12:33 AM, Ellery Crane wrote:

If I have a document with a collection field, and I have highlight
results on an item in such a collection, is there any way to identify
which item the match was on?

Here's an example:

curl -XDELETE 'http://127.0.0.1:9200/someindex?pretty=1'
curl -XPOST 'http://127.0.0.1:9200/someindex/user?pretty=1' -d '
{
"friends" : [
{
"name" : {
"first" : "Jack",
"last" : "Smith"
},
"email" : ["jack.smith@example.com",
"j.smith@example.com", "jack@smith.com", "jack@jacksmith.com"]
},
{
"name" : {
"first" : "Alice",
"last" : "Smith"
},
"email" : ["alice@example.com", "alice.smith@example.com"]
},
{
"name" : {
"first" : "Jack",
"last" : "Brown"
},
"email" : ["jb@example.com", "jack.brown@example.com",
"jack@example.com"]
}
]
}
'
curl -XGET 'http://127.0.0.1:9200/someindex/user/_search?pretty=1' -d
'
{
"query" : {
"query_string" : {
"query" : "jack",
"fields" : ["friends.name.first", "friends.name.last",
"friends.email"]
}
},
"highlight" : {
"fields" : {
"friends.name.first" : {},
"friends.name.last" : {},
"friends.email" : {}
}
}
}
'

Executing that search gets back a hit with the following highlight
info:

"highlight" : {
"friends.email" : [ "jack@smith.com", "jack</
em>@jacksmith.com", "jack@example.com" ],
"friends.name.first" : [ "Jack", "Jack" ]
}

Is there some way to determine which friend object each hit came off
of? I'm used to a Spring nested path syntax such as
"friends[0].name.first" or "friends[2].email[1]" or the like, but as
far as I can tell there is nothing similar in ES. On a hit on
something like "friends.name.first", I'd like to be able to provide
the broader context (both first and last name of the friend that
matched), but without knowing which friend object had the match, it is
difficult to put that together.

On May 17, 2:17 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

No, there isn't...

Hmm. This would certainly be a nice feature to have :slight_smile:

In the meanwhile, I am considering denormalizing the nested fields
into 'aggregate' fields, that contain all of the context I need, and
searching on those. For instance, when indexing a user, denormalize
the friend names into "friendNames", each element of which would be a
string consisting of "{friend.name.first} {friend.name.last}". The
only problem here is that it pollutes my _source document with data
I'm only using to get contextual highlighting.. Does ES have any way
to set up such 'aggregate' fields automatically, perhaps as part of a
mapping definition? Or, alternatively, am I overlooking a better way
to achieve my goal (showing a highlight context that spans multiple
fields within a nested collection property)?