# Sorting multivalued dates is incorrect with large number of shards

**URL:** <https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219>\
**Category:** Elasticsearch\
**Created:** [August 4, 2016, 1:10pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219 "2016-08-04T13:10:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [August 4, 2016, 1:10pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219/1 "2016-08-04T13:10:46Z")

</div>

I have an index with 40 shards. When I sort a field with date type and it is multivalued, then I get the results sorted in incorrect order.

This is how the sort is built:

"PDate"{  
"order" : "desc",  
"missing" : "\_last",  
"mode" : "min"  
}

**The results all get as sort value -9223372036854775808**

I do not get this when I have an smaller index with a few shards. Then the results are ordered correct.

Is there a limitation (or even a bug) on sorting of multivalued fields with a large number of shards?

---

<div class="post-metadata">

**Author:** ![tanguy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy/32/6030_2.png) [@tanguy](https://discuss.elastic.co/u/tanguy)\
**Post date:** [August 4, 2016, 1:46pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219/2 "2016-08-04T13:46:50Z")

</div>

Hi,

> [@drjz](#):
>
> I do not get this when I have an smaller index with a few shards. Then the results are ordered correct.

Did you have the same documents as you had with 40 shards?

> [@drjz](#):
>
> Is there a limitation (or even a bug) on sorting of multivalued fields with a large number of shards?

As far as I know, no.

It looks like the documents that match your query have no PDate value, thus elasticsearch internally uses the `Long.MIN_VALUE` to sort them because `missing` is set to `_last` and `order` to `desc`. Using `Long.MIN_VALUE` helps to "push" documents with no PDate value to the end of the list but in your case only documents without PDate match your search query.

---

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [August 4, 2016, 2:16pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219/3 "2016-08-04T14:16:02Z")

</div>

> [@tanguy](#):
>
> Did you have the same documents as you had with 40 shards?

No, it's a much smaller subset.

> [@tanguy](#):
>
> It looks like the documents that match your query have no PDate value, thus elasticsearch internally uses the Long.MIN\_VALUE to sort them because missing is set to \_last and order to desc. Using Long.MIN\_VALUE helps to "push" documents with no PDate value to the end of the list but in your case only documents without PDate match your search query.

I see that also the \_missing mode value gets ignored. I retrieve the docs with the PDate field in the source, and then I see its value(s) present, and even fields with missing values get shown in the top. The sorting value is for each and every hit this:

> "sort":[-9223372036854775808]

---

<div class="post-metadata">

**Author:** ![drjz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drjz/32/972_2.png) [@drjz](https://discuss.elastic.co/u/drjz)\
**Post date:** [August 4, 2016, 2:31pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219/4 "2016-08-04T14:31:56Z")

</div>

Sorry, I found the resolution. The field was of nested type and I did not see this. My apologies.

---

<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:** [July 5, 2017, 10:30pm UTC](https://discuss.elastic.co/t/sorting-multivalued-dates-is-incorrect-with-large-number-of-shards/57219/5 "2017-07-05T22:30:04Z")

</div>


