About Nested Script Sort


(Richard Leonard) #1

How to Combine Script Sort and Nested Search and Sort

I know how to search a nested object and also how to sort by script sort.
How could they work together?....

Say I have doc as following
{
"id": 1,
"tag": [ { "desc": "a", "weight": 0.8 }, { "desc": "b", "weight": 0.6 }, { "desc": "c", "weight": 0.4 } ]
}

{
"id": 2,
"tag": [ { "desc": "a", "weight": 0.4 }, { "desc": "c", "weight": 0.7 } ]
}

{
"id": 3,
"tag": [ { "desc": "a", "weight": 2.0 } ]
}

I want to search for tag [a or c] and sort by sum of their weight
So I want
doc 3 > doc 1 > doc 2,
with weight is 2.0 > 0.8+0.4 > 0.4+0.7

How can I achieve that?


(Richard Leonard) #2

Anyone Help?


(Yannick Welsch) #3

Have a look at this:

https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-sorting.html


(system) #4

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