Get inner hits for nested query inside bool query

In the index, i have a task which has nested segments which further have nested labels.
problem - Search tasks and segments which have label LBL_A and label LBL_B.
and return matching tasks , matching segments within task, matching labels within matching segment.
By nature of problem , user is allowed to search for any combinations of labels. so i do a nested query for segments which has a bool query with must, should operators and multiple nested label queries inside it.
I am able to search and return matching segments. but i could not figure out how to return matching labels.
if i wrap bool query inside a nested query . must operator does not work because i need segments where there are two labels with respective label names and nested bool query looks for the two label names in the same label which does not match.
If i use inner hits with nested label query and then post process to compile all inner hits into one array, it does not for corner cases. example search for segments where lblA and lblB are present or lblC and lblD are present. if segment has lblA and lblB and lblC, it will match but it will also return lblC as inner hit.

the solution that i think would have worked is making bool query return inner hits. but bool query does not have inner hits option.

I hope i am able to explain the problem.

Mapping -

{
"mappings": {
"_doc": {
"dynamic": "strict",
"properties": {
"task_id": { "type": "integer" },
"created": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"segments": {
"type": "nested",
"dynamic": "strict",
"properties": {
"segment_id": { "type": "integer"},
"labels" : {
"type": "nested",
"dynamic": "strict",
"properties": {
"name": { "type": "keyword"}
}
}
}
}
}
}
}
}

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