# Conditional Sorting

**URL:** <https://discuss.elastic.co/t/conditional-sorting/13717>\
**Category:** Elasticsearch\
**Created:** [September 23, 2013, 12:13am UTC](https://discuss.elastic.co/t/conditional-sorting/13717 "2013-09-23T00:13:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alkaruzi](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@alkaruzi](https://discuss.elastic.co/u/alkaruzi)\
**Post date:** [September 23, 2013, 12:13am UTC](https://discuss.elastic.co/t/conditional-sorting/13717/1 "2013-09-23T00:13:10Z")

</div>

I have some documents that I would like to sort on a date field. For  
documents with date equal to a specified date, example today, and all dates  
after that I would like to sort ascending. For dates before the specified  
date I would like to sort in descending order.

Is this possible in ElasticSearch? If so could you suggest any literature  
or approach.

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 23, 2013, 12:28am UTC](https://discuss.elastic.co/t/conditional-sorting/13717/2 "2013-09-23T00:28:05Z")

</div>

I think I'd use in that case a custom score: [http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/)

Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 23 sept. 2013 à 02:13, Javid Al Karuzi [scorpitar@gmail.com](mailto:scorpitar@gmail.com) a écrit :

I have some documents that I would like to sort on a date field. For documents with date equal to a specified date, example today, and all dates after that I would like to sort ascending. For dates before the specified date I would like to sort in descending order.

Is this possible in ElasticSearch? If so could you suggest any literature or approach.

## Thanks

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:15am UTC](https://discuss.elastic.co/t/conditional-sorting/13717/3 "2017-07-06T02:15:12Z")

</div>


