# ES query sorting by date with custom missing value

**URL:** <https://discuss.elastic.co/t/es-query-sorting-by-date-with-custom-missing-value/138966>\
**Category:** Elasticsearch\
**Created:** [July 6, 2018, 5:26pm UTC](https://discuss.elastic.co/t/es-query-sorting-by-date-with-custom-missing-value/138966 "2018-07-06T17:26:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user3078523](https://avatars.discourse-cdn.com/v4/letter/u/b782af/32.png) [@user3078523](https://discuss.elastic.co/u/user3078523)\
**Post date:** [July 6, 2018, 5:26pm UTC](https://discuss.elastic.co/t/es-query-sorting-by-date-with-custom-missing-value/138966/1 "2018-07-06T17:26:47Z")

</div>

I have an index containing some documents with a date field:

```
"date": {
  "type": "date",
  "format": "date_optional_time"
}

```

The field is optional (some documents don't have that value).

I would like to run a query returning all documents sorted by the date field and setting missing value to **some specific custom date**.

Apparently in case of type `date`, missing value needs to be of type `long` which I guess is a timestamp in milliseconds.

**My question is:** What timezone to use when preparing a custom value?

It is not obvious for me since, when storing documents, I can pass dates as strings in a timezone-agnostic format.

If ES internally converts such strings to timestamps, then to prepare a custom missing date I would have to use the same timezone that ES uses for such conversions.

(It was tested on ES 5.6.9.)

Kind regards,  
MK

---

<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:** [August 3, 2018, 5:26pm UTC](https://discuss.elastic.co/t/es-query-sorting-by-date-with-custom-missing-value/138966/2 "2018-08-03T17:26:50Z")

</div>

Closed on August 3, 2018, 5:26pm UTC

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