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.