Итак, ваш второй 'inner_hits' перезаписывает первый. Вы можете дать каждому «имя», чтобы убедиться, что они оба возвращают:
{
'size': 10,
'query': {
'bool': {
'must': [{
'nested': {
'path': 'attributes',
'score_mode':
'avg', 'inner_hits': {'name': 'first'},
'query': {'bool': {
'must': [{'match': {'attributes.ename': 'n1'}},
{'match': {'attributes.sv': 'v1'}}]}}}},
{
'nested': {
'path': 'attributes',
'score_mode':
'avg',
'inner_hits': {'name': 'second'},
'query': {'bool': {
'must': [{'match': {'attributes.ename': 'n2'}},
{'match': {'attributes.sv': 'v2'}}]}}}}]
}
}
}
Но еще лучшим подходом может быть сведение всего этого к одному вложенному запросу с несколькими запросами must. Что-то вроде:
{
'size': 10,
'query': {
'nested': {
'path': 'attributes',
'score_mode': 'avg',
'inner_hits': {},
'query': {
'bool': {
'must': [
{'match': {'attributes.ename': 'n1'}},
{'match': {'attributes.ename': 'n2'}},
{'match': {'attributes.sv': 'v1'}},
{'match': {'attributes.sv': 'v2'}}
]
}
}
}
}
}