# Is this a bug of Elasticsearch sorting?

**URL:** <https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317>\
**Category:** Elasticsearch\
**Created:** [December 2, 2022, 3:22am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317 "2022-12-02T03:22:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![howe\_xiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/howe_xiao/32/100496_2.png) [@howe\_xiao](https://discuss.elastic.co/u/howe_xiao)\
**Post date:** [December 2, 2022, 3:22am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317/1 "2022-12-02T03:22:04Z")

</div>

Problem Description: A field of keyword type causes a shard retrieval failure with differernt size and from value.

Environment：Node-4, Shard-8, Version-8.0

This is my query DSL on Kibana:

```auto
POST myIndex/_search
{
  "from": 10,
  "size": 4,
  "timeout": "1m",
  "query": {...},
  "sort": [
    {
      "warn_level": {
        "order": "desc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

```

The sort field 'warn\_level' is a field of keyword type, it only has four values ["1", "2", "3", "4"]. And the response result shows:

```auto
{
  "took" : 281,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 1,
    "failures" : [
      {
        "shard" : 5,
        "index" : "myIndex",
        "node" : "Q3XOTW7gReK2hFI3xVu0bQ",
        "reason" : {
          "type" : "array_index_out_of_bounds_exception",
          "reason" : "Index -1 out of bounds for length 1"
        }
      }
    ]
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

But sometimes this query DSL is works and no error occurs.  
Then I tried to use other keyword type fields to sort, and the same error occurred.

I just want to know what is causing this problem, thanks very much.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 2, 2022, 3:30am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317/2 "2022-12-02T03:30:36Z")

</div>

Welcome to our community! 😃

Can you share the mapping for your index?

---

<div class="post-metadata">

**Author:** ![howe\_xiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/howe_xiao/32/100496_2.png) [@howe\_xiao](https://discuss.elastic.co/u/howe_xiao)\
**Post date:** [December 2, 2022, 3:36am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317/3 "2022-12-02T03:36:46Z")

</div>

For confidentiality, this is part of index mapping, and i use the 'warn\_level' field to sort:

```auto
{
  "myIndex" : {
    "mappings" : {
      "dynamic" : "true",
      "properties" : {
        "a_audio_feature_vector_id" : {
          "type" : "keyword"
        },
        "a_audio_lang" : {
          "type" : "text"
        },
        "a_audio_trans_content" : {
          "type" : "text"
        },
        "a_logo" : {
          "type" : "text"
        },
        "a_ocr_position" : {
          "type" : "keyword"
        },
        "warn_level" : {
          "type" : "keyword"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![howe\_xiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/howe_xiao/32/100496_2.png) [@howe\_xiao](https://discuss.elastic.co/u/howe_xiao)\
**Post date:** [December 2, 2022, 7:25am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317/4 "2022-12-02T07:25:46Z")

</div>

My index mapping is blow your post

---

<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:** [December 30, 2022, 7:26am UTC](https://discuss.elastic.co/t/is-this-a-bug-of-elasticsearch-sorting/320317/5 "2022-12-30T07:26:02Z")

</div>

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