# Can elasticsearch list the latest X number of indexed documents across all indexes?

**URL:** https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262
**Category:** Elasticsearch
**Created:** [June 4, 2013, 7:41pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262 "2013-06-04T19:41:49Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mikael\_Andersson](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Mikael\_Andersson](https://discuss.elastic.co/u/Mikael_Andersson)
#### Post date: [June 4, 2013, 7:41pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/1 "2013-06-04T19:41:49Z")

</div>

Hi  
I'm a complete elasticsearch/lucene newbie and I've been given a  
requirement which I'm wondering if elasticsearch can help me with.

I work on a Grails application where we have a bunch of information which  
we would like to display to users in a "timeline" fashion, a bit on their  
welcome page where we list the latest news, articles, document uploads, etc.  
All these grails domain objects have a lastUpdated timestamp which I'm  
hoping to order by, as well as provide some index specific criteria if  
possible.

First off is it possible to simply fetch the latest X number of documents  
without any filtering by query parameters?

Sorry for this trivial question but thought I'd go down the lazy route and  
simply ask 🙂

Many thanks,  
Micke

--  
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: ![shadyabhi](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shadyabhi](https://discuss.elastic.co/u/shadyabhi)
#### Post date: [June 5, 2013, 3:31pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/2 "2013-06-05T15:31:14Z")

</div>

When a document goes to ES, ES by itself (if not provided) just gives it a  
id and parses fields etc. It doesn't have any notion of when was the  
document added.

So, you'll have to have a field that'll keep track of when a doc was added.

On Wed, Jun 5, 2013 at 1:11 AM, Mikael Andersson [mail.micke@gmail.com](mailto:mail.micke@gmail.com)wrote:

> Hi  
> I'm a complete elasticsearch/lucene newbie and I've been given a  
> requirement which I'm wondering if elasticsearch can help me with.
> 
> I work on a Grails application where we have a bunch of information which  
> we would like to display to users in a "timeline" fashion, a bit on their  
> welcome page where we list the latest news, articles, document uploads, etc.  
> All these grails domain objects have a lastUpdated timestamp which I'm  
> hoping to order by, as well as provide some index specific criteria if  
> possible.
> 
> First off is it possible to simply fetch the latest X number of documents  
> without any filtering by query parameters?
> 
> Sorry for this trivial question but thought I'd go down the lazy route and  
> simply ask 🙂
> 
> Many thanks,  
> Micke
> 
> --  
> 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).

--  
Regards,  
Abhijeet Rastogi (shadyabhi)  
[http://blog.abhijeetr.com](http://blog.abhijeetr.com)

--  
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: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 5, 2013, 3:51pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/3 "2013-06-05T15:51:04Z")

</div>

Hey,

you could simply sort the documents by the last updated timestamp and do a  
query\_all query, plus specifying the size, like this for your tests

curl -X POST localhost:9200/twitter/tweet/\_search -d '{ "size":5, "query" :  
{ "match\_all":{} } , "sort" : [{ "\_timestamp" : { "order":"asc" } }] }'

hope this helps

--Alex

On Tue, Jun 4, 2013 at 9:41 PM, Mikael Andersson [mail.micke@gmail.com](mailto:mail.micke@gmail.com)wrote:

> Hi  
> I'm a complete elasticsearch/lucene newbie and I've been given a  
> requirement which I'm wondering if elasticsearch can help me with.
> 
> I work on a Grails application where we have a bunch of information which  
> we would like to display to users in a "timeline" fashion, a bit on their  
> welcome page where we list the latest news, articles, document uploads, etc.  
> All these grails domain objects have a lastUpdated timestamp which I'm  
> hoping to order by, as well as provide some index specific criteria if  
> possible.
> 
> First off is it possible to simply fetch the latest X number of documents  
> without any filtering by query parameters?
> 
> Sorry for this trivial question but thought I'd go down the lazy route and  
> simply ask 🙂
> 
> Many thanks,  
> Micke
> 
> --  
> 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: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [June 5, 2013, 7:21pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/4 "2013-06-05T19:21:00Z")

</div>

FYI, the timestamp feature is disabled by default:

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

Enabling it with the defaults and using Alex's example would be the ideal  
solution.

--  
Ivan

On Wed, Jun 5, 2013 at 8:51 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> you could simply sort the documents by the last updated timestamp and do a  
> query\_all query, plus specifying the size, like this for your tests
> 
> curl -X POST localhost:9200/twitter/tweet/\_search -d '{ "size":5, "query"  
> : { "match\_all":{} } , "sort" : [{ "\_timestamp" : { "order":"asc" } }] }'
> 
> hope this helps
> 
> --Alex
> 
> On Tue, Jun 4, 2013 at 9:41 PM, Mikael Andersson [mail.micke@gmail.com](mailto:mail.micke@gmail.com)wrote:
> 
> > Hi  
> > I'm a complete elasticsearch/lucene newbie and I've been given a  
> > requirement which I'm wondering if elasticsearch can help me with.
> > 
> > I work on a Grails application where we have a bunch of information which  
> > we would like to display to users in a "timeline" fashion, a bit on their  
> > welcome page where we list the latest news, articles, document uploads, etc.  
> > All these grails domain objects have a lastUpdated timestamp which I'm  
> > hoping to order by, as well as provide some index specific criteria if  
> > possible.
> > 
> > First off is it possible to simply fetch the latest X number of documents  
> > without any filtering by query parameters?
> > 
> > Sorry for this trivial question but thought I'd go down the lazy route  
> > and simply ask 🙂
> > 
> > Many thanks,  
> > Micke
> > 
> > --  
> > 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).

--  
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: ![Mikael\_Andersson](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Mikael\_Andersson](https://discuss.elastic.co/u/Mikael_Andersson)
#### Post date: [June 5, 2013, 9:27pm UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/5 "2013-06-05T21:27:10Z")

</div>

Brilliant

Been playing around with this and indeed it does seem to do exactly what I  
want, even by simply switching the \_timestamp for in my case lastUpdated.

Next step is to figure out how I can add custom filtering to each of the  
different documents : )

Many thanks for the info, just what I needed.

- Micke

On Wednesday, June 5, 2013 4:51:04 PM UTC+1, Alexander Reelsen wrote:

> Hey,
> 
> you could simply sort the documents by the last updated timestamp and do a  
> query\_all query, plus specifying the size, like this for your tests
> 
> curl -X POST localhost:9200/twitter/tweet/\_search -d '{ "size":5, "query"  
> : { "match\_all":{} } , "sort" : [{ "\_timestamp" : { "order":"asc" } }] }'
> 
> hope this helps
> 
> --Alex
> 
> On Tue, Jun 4, 2013 at 9:41 PM, Mikael Andersson \<[mail....@gmail.com](mailto:mail....@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi  
> > I'm a complete elasticsearch/lucene newbie and I've been given a  
> > requirement which I'm wondering if elasticsearch can help me with.
> > 
> > I work on a Grails application where we have a bunch of information which  
> > we would like to display to users in a "timeline" fashion, a bit on their  
> > welcome page where we list the latest news, articles, document uploads, etc.  
> > All these grails domain objects have a lastUpdated timestamp which I'm  
> > hoping to order by, as well as provide some index specific criteria if  
> > possible.
> > 
> > First off is it possible to simply fetch the latest X number of documents  
> > without any filtering by query parameters?
> > 
> > Sorry for this trivial question but thought I'd go down the lazy route  
> > and simply ask 🙂
> > 
> > Many thanks,  
> > Micke
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 6, 2013, 8:18am UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/6 "2013-06-06T08:18:24Z")

</div>

Hey,

just a side note, if the entities you are indexing are GORM based entities,  
you simply index the lastUpdated timestamp, make sure it is a timestamp  
when indexing, and do not need the \_timestamp functionality at all.

But maybe I got you wrong here, so if you current solution works, I am fine  
with that as well 😉

--Alex

On Wed, Jun 5, 2013 at 11:27 PM, Mikael Andersson [mail.micke@gmail.com](mailto:mail.micke@gmail.com)wrote:

> Brilliant
> 
> Been playing around with this and indeed it does seem to do exactly what I  
> want, even by simply switching the \_timestamp for in my case lastUpdated.
> 
> Next step is to figure out how I can add custom filtering to each of the  
> different documents : )
> 
> Many thanks for the info, just what I needed.
> 
> - Micke
> 
> On Wednesday, June 5, 2013 4:51:04 PM UTC+1, Alexander Reelsen wrote:
> 
> > Hey,
> > 
> > you could simply sort the documents by the last updated timestamp and do  
> > a query\_all query, plus specifying the size, like this for your tests
> > 
> > curl -X POST localhost:9200/twitter/tweet/\_\*\*search -d '{ "size":5,  
> > "query" : { "match\_all":{} } , "sort" : [ { "\_timestamp" : { "order":"asc"  
> > } } ] }'
> > 
> > hope this helps
> > 
> > --Alex
> > 
> > On Tue, Jun 4, 2013 at 9:41 PM, Mikael Andersson [mail....@gmail.com](mailto:mail....@gmail.com)wrote:
> > 
> > > Hi  
> > > I'm a complete elasticsearch/lucene newbie and I've been given a  
> > > requirement which I'm wondering if elasticsearch can help me with.
> > > 
> > > I work on a Grails application where we have a bunch of information  
> > > which we would like to display to users in a "timeline" fashion, a bit on  
> > > their welcome page where we list the latest news, articles, document  
> > > uploads, etc.  
> > > All these grails domain objects have a lastUpdated timestamp which I'm  
> > > hoping to order by, as well as provide some index specific criteria if  
> > > possible.
> > > 
> > > First off is it possible to simply fetch the latest X number of  
> > > documents without any filtering by query parameters?
> > > 
> > > Sorry for this trivial question but thought I'd go down the lazy route  
> > > and simply ask 🙂
> > > 
> > > Many thanks,  
> > > Micke
> > > 
> > > --  
> > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[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).

--  
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:32am UTC](https://discuss.elastic.co/t/can-elasticsearch-list-the-latest-x-number-of-indexed-documents-across-all-indexes/12262/7 "2017-07-06T02:32:40Z")

</div>


