I have the elastic search cluster of the form:
{
"_id":"xxxx"
"contents":[
{
"name":"abc",
"age":"24"
}
]
},
{
"_id":"yyyy"
"contents":[
{
"name":"xyz",
"age":"25"
},
{
"name":"pqr",
"age":"29"
},
]
}
I have to perform a sort based query on the size of the object array field 'contents'.
I have tried:
{
"size": 10,
"from": 0,
"query": {
"match_all": {}
},
"sort" : {
"_script" : {
"script": "doc['contents.name'].values.size()",
"order": "desc",
"type" : "string",
}
}
}
The above query sometime gives me the correct result, but most of the times it fails to give the results in sorted order.
type : number?