Hello! I am using elasticsearch version 7.11 and I want to sort items by the array of numbers: lucky_numbers.number_list
A have a lot of elements like below and arrays have a dynamic length, example:
_source {
"game.name": "Twisted Game",
"lucky_numbers": [
{
"number_list": "9"
},
{
"number_list": "11"
},
{
"number_list": "102"
}
]
},
....
_source {
"game.name": "Number Roulette",
"lucky_numbers": [
{
"number_list": "10"
},
{
"number_list": "11"
},
{
"number_list": "99"
},
{
"number_list": "102"
}
]
},
....
_source {
"game.name": "Numeric Odyssey",
"lucky_numbers": [
{
"number_list": "9"
},
{
"number_list": "12"
},
{
"number_list": "100"
}
]
}
If I use a sorting script and concatenate these sorted numbers into a string, I get the order:
"10,11,99,102"
"9,11,102",
"9,12,100"
But I want the correct numerical order:
"9,11,102",
"9,12,100"
"10,11,99,102"
How can I do this? I know that sort have e.g. option mode:min for arrays, but I want to consider all numbers in array, not just the lowest value. Can I write my own comparator?