As an example imagine
Mapping
OuterObject contains nested NestedObject.
Data
OuterObject1 contains NestedObject1, NestedObject2
OuterObject2 contains NestedObject3, NestedObject4
Desired Results (using a nested filter)
4 hits
- OuterObject1 and NestedObject1
- OuterObject1 and NestedObject2
- OuterObject2 and NestedObject3
- OuterObject2 and NestedObject4
If I use inner hits then the results look like this
- OuterObject1, inner_hits = NestedObject1, NestedObject2
- OuterObject2, inner_hits = NestedObject3, NestedObject4
I can then programmatically rewrite these results into the format I want and pretend the 2 hits are actually 4 hits.
Sorting
The problem comes when I then try and sort my results by a field in NestedObject.
I want a sort that compares
NestedObject1 vs NestedObject2 vs NestedObject3 vs NestedObject4
The sort within inner_hits separately compares
NestedObject1 vs NestedObject2
NestedObject3 vs NestedObject4
Sorting using nested sort compares
NestedObject1 vs NestedObject3 (one NestedObject from OuterObject1 and one from OuterObject2)
Questions
- Am I misunderstanding Elasticsearch sorting?
- Is there a way to convert inner_hits to normal hits? I.e. so if I match 2 NestedObjects then I get 2 separate hits. This would avoid me programmatically 'pulling out' hits from inner_hits.
- How can I sort NestedObject1 vs NestedObject2 vs NestedObject3 vs NestedObject4
Thanks all in advance!