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

**URL:** https://discuss.elastic.co/t/sort-by-a-field-containing-array-of-strings-with-sort-mode-min/273215
**Category:** Elasticsearch
**Created:** [May 17, 2021, 8:01pm UTC](https://discuss.elastic.co/t/sort-by-a-field-containing-array-of-strings-with-sort-mode-min/273215 "2021-05-17T20:01:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![curlyheads](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@curlyheads](https://discuss.elastic.co/u/curlyheads)
#### Post date: [May 17, 2021, 8:01pm UTC](https://discuss.elastic.co/t/sort-by-a-field-containing-array-of-strings-with-sort-mode-min/273215/1 "2021-05-17T20:01:38Z")

</div>

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](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!

---

<div class="post-metadata">

### Author: ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)
#### Post date: [May 19, 2021, 9:57pm UTC](https://discuss.elastic.co/t/sort-by-a-field-containing-array-of-strings-with-sort-mode-min/273215/2 "2021-05-19T21:57:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 16, 2021, 9:58pm UTC](https://discuss.elastic.co/t/sort-by-a-field-containing-array-of-strings-with-sort-mode-min/273215/3 "2021-06-16T21:58:45Z")

</div>

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