# Sort based on day

**URL:** <https://discuss.elastic.co/t/sort-based-on-day/11824>\
**Category:** Elasticsearch\
**Created:** [May 6, 2013, 4:23am UTC](https://discuss.elastic.co/t/sort-based-on-day/11824 "2013-05-06T04:23:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [May 6, 2013, 4:23am UTC](https://discuss.elastic.co/t/sort-based-on-day/11824/1 "2013-05-06T04:23:00Z")

</div>

Hi ,

I am trying to implement a sort on the resulting set based on following  
criteria

- Last 24 hours of data should get the highest priority. Previous should  
be getting the next and so on. ( I have a time feild which stores the time  
of the feed)
- And on a the last 24 hours of feeds , the feed with greatest value for  
the field count should come first. The same with the rest.

So this is a combination of time field and number field.

How can this be achieved using sort ?

Thanks

```
        Vineeth

```

--  
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:** ![Robin\_Verlangen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_verlangen/32/1542_2.png) [@Robin\_Verlangen](https://discuss.elastic.co/u/Robin_Verlangen)\
**Post date:** [May 6, 2013, 6:11am UTC](https://discuss.elastic.co/t/sort-based-on-day/11824/2 "2013-05-06T06:11:43Z")

</div>

Hi Vineeth,

I think "Script based sorting" is what you need:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

E.g.

{  
"query" : {  
....  
},  
"sort" : {  
"\_script" : {  
"script" : "doc['field\_name'].value \* factor",  
"type" : "number",  
"params" : {  
"factor" : 1.1  
},  
"order" : "asc"  
}  
}  
}

Best regards,

Robin Verlangen  
_Data Architect_  
\*  
\*  
W [http://www.robinverlangen.nl](http://www.robinverlangen.nl)  
E robin@us2.nl

[http://goo.gl/Lt7BC](http://goo.gl/Lt7BC)

Disclaimer: The information contained in this message and attachments is  
intended solely for the attention and use of the named addressee and may be  
confidential. If you are not the intended recipient, you are reminded that  
the information remains the property of the sender. You must not use,  
disclose, distribute, copy, print or rely on this e-mail. If you have  
received this message in error, please contact the sender immediately and  
irrevocably delete this message and any copies.

On Mon, May 6, 2013 at 6:23 AM, Vineeth Mohan [vineethmohan@algotree.com](mailto:vineethmohan@algotree.com)wrote:

> Hi ,
> 
> I am trying to implement a sort on the resulting set based on following  
> criteria
> 
> - Last 24 hours of data should get the highest priority. Previous  
> should be getting the next and so on. ( I have a time feild which stores  
> the time of the feed)
> - And on a the last 24 hours of feeds , the feed with greatest value  
> for the field count should come first. The same with the rest.
> 
> So this is a combination of time field and number field.
> 
> How can this be achieved using sort ?
> 
> Thanks
> 
> ```
> Vineeth
> 
> ```
> 
> --  
> 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:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [May 6, 2013, 7:01am UTC](https://discuss.elastic.co/t/sort-based-on-day/11824/3 "2013-05-06T07:01:10Z")

</div>

Add a boost to your documents in respect to the time stamp value.

Idea is to use timestamp for boost, e.g. 1.0 = day 1, 2.0 = day 2, 3.0 =  
day 3 ... n = day n

Then you do not need to sort. Sort is evil.

Jörg

Am 06.05.13 06:23, schrieb Vineeth Mohan:

> Hi ,
> 
> I am trying to implement a sort on the resulting set based on  
> following criteria
> 
> - Last 24 hours of data should get the highest priority. Previous  
> should be getting the next and so on. ( I have a time feild which  
> stores the time of the feed)
> - And on a the last 24 hours of feeds , the feed with greatest value  
> for the field count should come first. The same with the rest.
> 
> So this is a combination of time field and number field.
> 
> How can this be achieved using sort ?

--  
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:38am UTC](https://discuss.elastic.co/t/sort-based-on-day/11824/4 "2017-07-06T02:38:10Z")

</div>


