Search code examples
elasticsearchelastic-stackelasticsearch-5

how to get only the branch of the searched elastic nested object


i have a big elastic search nested object. But when queried for the inner nested objects - the nested queries always return the root. is it possible to return only the branch of the nested object that i search for?

for example, my nested object:

root: 
{
  NestedObjectA: 
    {valueA: 1, 
     array_of_nested_B_objects: 
       [{valueB: 2}, {valueB:3}] 
    }
}

so if i search for an object in array_of_nested_B_objects with value 3 - i dont want to get the object with value 2 at all.

thnx


Solution

  • You can use inner_hits in your nested query, to get only the nested object in the result that matched your query