Sorting on Nested array object within the same json file

Hi,

I'm trying to sort the fields present within an array which is of type nested.

My data :

{
"name" : "abc",
"shipping":[
{
"shipmentcode" : 5,
"shipmentstatus" : "resolved",
"shipmentorderid": "12345"
},
{
"shipmentcode" : 4,
"shipmentstatus" : "delivered",
"shipmentorderid": "12345"
},
{
"shipmentcode" : 1,
"shipmentstatus" : "orderconfirmed",
"shipmentorderid": "12345"
},
{
"shipmentcode" : 2,
"shipmentstatus" : "RTF",
"shipmentorderid": "12345"
},
{
"shipmentcode" : 3,
"shipmentstatus" : "shipped","shipmentorderid": "12345"
}
]
}

In here, I have to run a query a term query to find the docs that matches name to "abc" and in that result I have to sort the shipping array based on the "shipmentcode"..something like the below when sorter in desc order-

"shipping" : [
{
"shipmentcode" : 5,
"shipmentstatus" : "resolved",
"shipmentorderid" : "12345"
},
{
"shipmentcode" : 4,
"shipmentstatus" : "delivered",
"shipmentorderid" : "12345"
},
{
"shipmentcode" : 3,
"shipmentstatus" : "shipped",
"shipmentorderid" : "12345"
},
{
"shipmentcode" : 2,
"shipmentstatus" : "RTF",
"shipmentorderid" : "12345"
},
{
"shipmentcode" : 1,
"shipmentstatus" : "orderconfirmed",
"shipmentorderid" : "12345"
}
]
Is this even possible in elasticsearch? I have to sort on the result!!

If it is one single document, it is shown exactly as you sent it. No internal sorting of arrays then.

But if you index instead every shipping as a single document, then that'd be possible.

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