# ES 1.2.1 sort by \_timestamp

**URL:** https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064
**Category:** Elasticsearch
**Created:** [June 12, 2014, 12:13pm UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064 "2014-06-12T12:13:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan\_Eberl](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stefan\_Eberl](https://discuss.elastic.co/u/Stefan_Eberl)
#### Post date: [June 12, 2014, 12:13pm UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/1 "2014-06-12T12:13:07Z")

</div>

Hey all,

I have a question regarding sorting by \_timestamp.

The \_timestamp "enabled" setting is set to true, everything else is not  
explicitly specified (so I assume default values are used).  
I have an application inserting new documents periodically and I would  
assume that \_timestamp gets filled with the current timestamp.

After a while I perform the following sort  
curl -XPOST '[http://localhost:9200/my\_index/my\_type/\_search?pretty](http://localhost:9200/my_index/my_type/_search?pretty)' -d ' {  
"sort" : [  
{ "\_timestamp" : {"order" : "desc" } }  
]  
}

I would expect to always get the last 10 inserted documents, which is not  
the case.  
Sometimes I get the most recent ones, sometimes I get some historical data.

Thanks for your help.

BR,  
Stefan

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [June 12, 2014, 3:31pm UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/2 "2014-06-12T15:31:32Z")

</div>

Do you set timestamp value from you client or do you let ES fill them for  
you?

Do you run more than one node? Are the clocks on your nodes running  
synchronously?

Jörg

On Thu, Jun 12, 2014 at 2:13 PM, Stefan Eberl [cpppwner@gmail.com](mailto:cpppwner@gmail.com) wrote:

> Hey all,
> 
> I have a question regarding sorting by \_timestamp.
> 
> The \_timestamp "enabled" setting is set to true, everything else is not  
> explicitly specified (so I assume default values are used).  
> I have an application inserting new documents periodically and I would  
> assume that \_timestamp gets filled with the current timestamp.
> 
> After a while I perform the following sort  
> curl -XPOST '[http://localhost:9200/my\_index/my\_type/\_search?pretty](http://localhost:9200/my_index/my_type/_search?pretty)' -d ' {  
> "sort" : [  
> { "\_timestamp" : {"order" : "desc" } }  
> ]  
> }
> 
> I would expect to always get the last 10 inserted documents, which is not  
> the case.  
> Sometimes I get the most recent ones, sometimes I get some historical data.
> 
> Thanks for your help.
> 
> BR,  
> Stefan
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFVuicgKrdrAXKWsT3FgQFccXtXOTXuJi9-q3-bWJJpYg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFVuicgKrdrAXKWsT3FgQFccXtXOTXuJi9-q3-bWJJpYg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Eberl](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stefan\_Eberl](https://discuss.elastic.co/u/Stefan_Eberl)
#### Post date: [June 12, 2014, 4:49pm UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/3 "2014-06-12T16:49:04Z")

</div>

> Do you set timestamp value from you client or do you let ES fill them for  
> you?

I let ES fill that value.

> Do you run more than one node? Are the clocks on your nodes running  
> synchronously?

Only one node is storing data, the remaining nodes are client nodes only.  
Clocks are synchronized with a time server.

BR,  
Stefan

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/27edfe03-f8d7-4114-95dc-129b7b6e7bfb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/27edfe03-f8d7-4114-95dc-129b7b6e7bfb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)
#### Post date: [June 12, 2014, 4:51pm UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/4 "2014-06-12T16:51:59Z")

</div>

This is weird. Are you sure what you are seeing is not overridden documents  
(can happen if you specify the ID yourself)? Can you add the \_timestamp  
field to the results and verify the documents are indeed not sorted by  
\_timestamp?

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Thu, Jun 12, 2014 at 3:13 PM, Stefan Eberl [cpppwner@gmail.com](mailto:cpppwner@gmail.com) wrote:

> Hey all,
> 
> I have a question regarding sorting by \_timestamp.
> 
> The \_timestamp "enabled" setting is set to true, everything else is not  
> explicitly specified (so I assume default values are used).  
> I have an application inserting new documents periodically and I would  
> assume that \_timestamp gets filled with the current timestamp.
> 
> After a while I perform the following sort  
> curl -XPOST '[http://localhost:9200/my\_index/my\_type/\_search?pretty](http://localhost:9200/my_index/my_type/_search?pretty)' -d ' {  
> "sort" : [  
> { "\_timestamp" : {"order" : "desc" } }  
> ]  
> }
> 
> I would expect to always get the last 10 inserted documents, which is not  
> the case.  
> Sometimes I get the most recent ones, sometimes I get some historical data.
> 
> Thanks for your help.
> 
> BR,  
> Stefan
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1d81d216-f393-4618-afb7-74d71aa7841c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zu8xcCKvC\_joOdGDCKc7SMamOJh1W2jfqs4%3Dh8g%2BbysHg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zu8xcCKvC_joOdGDCKc7SMamOJh1W2jfqs4%3Dh8g%2BbysHg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Eberl](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stefan\_Eberl](https://discuss.elastic.co/u/Stefan_Eberl)
#### Post date: [June 13, 2014, 8:26am UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/5 "2014-06-13T08:26:09Z")

</div>

On Thursday, June 12, 2014 6:52:16 PM UTC+2, Itamar Syn-Hershko wrote:

> This is weird. Are you sure what you are seeing is not overridden  
> documents (can happen if you specify the ID yourself)? Can you add the  
> \_timestamp field to the results and verify the documents are indeed not  
> sorted by \_timestamp?

The id is also automatically generated by ES.  
Do i need to store the \_timestamp field to be able to retrieve it using  
"fields" : ["\_timestamp"] in my query?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)
#### Post date: [June 13, 2014, 8:31am UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/6 "2014-06-13T08:31:35Z")

</div>

Possibly, because it's not provided in the \_source, or just use this:

> **[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.

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Jun 13, 2014 at 11:26 AM, Stefan Eberl [cpppwner@gmail.com](mailto:cpppwner@gmail.com) wrote:

> On Thursday, June 12, 2014 6:52:16 PM UTC+2, Itamar Syn-Hershko wrote:
> 
> > This is weird. Are you sure what you are seeing is not overridden  
> > documents (can happen if you specify the ID yourself)? Can you add the  
> > \_timestamp field to the results and verify the documents are indeed not  
> > sorted by \_timestamp?
> 
> The id is also automatically generated by ES.  
> Do i need to store the \_timestamp field to be able to retrieve it using  
> "fields" : ["\_timestamp"] in my query?
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c1190f3b-2707-4b1e-9151-5967a7a54733%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvRD%3DbHqX-snqSLV9p%3D%3DA3KEwhP%3DNHAiH6m%2BMz2AhRvAQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvRD%3DbHqX-snqSLV9p%3D%3DA3KEwhP%3DNHAiH6m%2BMz2AhRvAQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Eberl](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stefan\_Eberl](https://discuss.elastic.co/u/Stefan_Eberl)
#### Post date: [June 13, 2014, 9:49am UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/7 "2014-06-13T09:49:48Z")

</div>

On Friday, June 13, 2014 10:31:53 AM UTC+2, Itamar Syn-Hershko wrote:

> Possibly, because it's not provided in the \_source, or just use this:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html#_path_2)
> 
> So your suggestion is to have my app fill an additional field, which then  
> gets's mapped to \_timestamp, correct?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)
#### Post date: [June 13, 2014, 10:01am UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/8 "2014-06-13T10:01:55Z")

</div>

This is just to debug this, to make sure results are indeed not sorted by  
\_timestamp, as you claim. Probably easier to just set \_timestamp to stored.

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Jun 13, 2014 at 12:49 PM, Stefan Eberl [cpppwner@gmail.com](mailto:cpppwner@gmail.com) wrote:

> On Friday, June 13, 2014 10:31:53 AM UTC+2, Itamar Syn-Hershko wrote:
> 
> > Possibly, because it's not provided in the \_source, or just use this:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/mapping-timestamp-field.html#\_path\_2
> > 
> > So your suggestion is to have my app fill an additional field, which then  
> > gets's mapped to \_timestamp, correct?
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d68a20f4-8234-4bfc-b4ee-d135f948dda5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZuuCpjAnQhGM3WnKuPd8VcgD3X\_HqDcf7MA%2B%3D7dYRcjxg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZuuCpjAnQhGM3WnKuPd8VcgD3X_HqDcf7MA%2B%3D7dYRcjxg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:22am UTC](https://discuss.elastic.co/t/es-1-2-1-sort-by--timestamp/18064/9 "2017-07-06T01:22:46Z")

</div>


