Sort by a field containing array of strings with sort mode min

Hi everybody,

I want to sort the following example documents by the first array value of the field "name":

curl -X PUT "localhost:9200/my-index-000001/_doc/1?refresh&pretty" -H 'Content-Type: 
application/json' -d'
{
   "name": ["arthor", "chris"]
}
'
curl -X PUT "localhost:9200/my-index-000001/_doc/2?refresh&pretty" -H 'Content-Type: 
application/json' -d'
{
   "name": ["bunis", "bunas"]
}
'
curl -X PUT "localhost:9200/my-index-000001/_doc/3?refresh&pretty" -H 'Content-Type: 
application/json' -d'
{
   "name": ["chris", "arthor"]
}
'

with the following query:

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
   "query" : {
      "wildcard" : {
          "name" : {
              "value" :"*"
           }
       }
   },
   "sort" : [
      {"name.keyword" : {"order" : "asc", "mode" : "min"}}
   ]
}
'

But the result is:

  1. ["arthor", "chris"]
  2. ["chris", "arthor"]
  3. ["bunis", "bunas"]

I would expect the following result:

  1. ["arthor", "chris"]
  2. ["bunis", "bunas"]
  3. ["chris", "arthor"]

as hinted in the reference docs:

https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#_sort_mode_option

by the sort mode option.

Is this a bug or just not intended for arrays of strings?

Elasticsearch version used: 7.12.1

Thanks in advance for any help!

There is no order in array values. Internally they will be sorted and stored alphabetically. For sort mode "min" for each document a minimum value from these values are chosen.
If you need an order, you need to present each option as a nested document.

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