Q: Elastic sorting by one specific nested item I have products that might belong to a preordered list. Each product has been indexed with following structure:
product:{"id":123, "lists": [{"id":2,"position":4},{"id":6,"position":1}]}

I want to list products with criteria lists.id == 2 and that works fine.
How to do sorting in Elastic search query by position in list so that the position of the specified list id is used? Nested sorting doesn't help as I cannot define which one of the nested items I want to use for sorting.
https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-sorting.html
At the moment I am experimenting with script_score but not too much progress there. 
Changing the structure of the mapping is also possible.

A: Alright, looks like I had a flaw in my mappings. It lacked the required "type":"nested" for the list and therefore the nested sorting did not work. 

A: As per my understanding sorting by position:


var dataList = {"lists": [{"id":2,"position":4},{"id":6,"position":1}]}
dataList.lists.sort(function(a,b){
 return a.position - b.position;
})

console.log(dataList);


