elasticsearch/elasticsearch — Issue #1764: [Feature request] Highlighting with parent/child queries
Author: Vineeth-Mohan
Created: 2012-03-06 21:12:57+00:00
State: open

docID and the highlighted part of the matched document needs to be given back.

Requirement

On the query side, we would specify we want the children to be returned along with their parent data, and optionally some highlighting on the children fields.
{
"query": {
"top_children" : {
"type": "subcontent",
"query" : {
"term" : {
"name" : "bike"
}
}
"score" : "max",
"factor" : 5,
"incremental_factor" : 2
}
},
"children": { // just having this tags means we at least want the ids of the children
"size" : 2, // maximum number of children by parent to return
"full_data" : false, // if true return not just the id of the child but also its data
"highlight" : { // same syntax as for normal queries
"fields" : {
"name" : {}
}
}
}
}

Then as results we would have something like:
"hits" : {
"total" : 7,
"max_score" : 3.366573
"hits" : [
{
"_index" : "es",
"_type" : "twitter",
"_id" : 8001,
"_score" : 3.366573,
"children": {
"total" : 4,
"hits" : [ // hits on children of this current parent, ordered by score
{
"_id" : 654,
"highlight" : {
"name" : [ "my lovely bike" ]
}
},
{
"_id" : 987,
"highlight" : {
"name" : [ "my nice bike" ]
}
}
]
}
},
{
"_index" : "es",
"_type" : "twitter",
"_id" : 8004,
.... etc....
}

Efforts in this direction is documented here - http://elasticsearch-users.115913.n3.nabble.com/Highlighting-with-parent-child-queries-td3275351.html