Returning the child fields next to matched field

Assume that I have a document like below

{
"_index": "sample",
"_type": "doc",
"_id": "student_id_1",
"_version":2,
"_score":1,
"_source":
{
"title": "Higher secondary",
"DOJ":2020-06-23,
"S_id":"SH123",
"first_name":"Gopiraj",
"last_name":"Muthusamy"
"subjects":[
{
"name":"english"
"type":"communication"
"sub_id":1
},{
"name":"Maths"
"type":"learning"
"sub_id":2
},{
"name":"science"
"type":"learning"
"sub_id":3
}]
}
}

from the above document i using highlight method to display the macthed field and its value but its not returning other fields inside the hash, for example the word that i need to search for is "learning", I'm expecting ES should return like below in highlight or in any other form

[
{
"sub_id":2,
"type":"learning"
},{
"sub_id":3,
"type":"learning"
}
]

Please guide

does highlight_query inside highlight will work? I know that highlight_query is used to work on the resultant data but still is there is any chance of getting the results expected above?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.