# Searching most recent objects

**URL:** https://discuss.elastic.co/t/searching-most-recent-objects/17036
**Category:** Elasticsearch
**Created:** [April 16, 2014, 1:24am UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036 "2014-04-16T01:24:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Joris\_Bolsens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joris_bolsens/32/1648_2.png) [@Joris\_Bolsens](https://discuss.elastic.co/u/Joris_Bolsens)
#### Post date: [April 16, 2014, 1:24am UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/1 "2014-04-16T01:24:52Z")

</div>

I am using the javascript API and want to do a search and have it search  
through the most recent objects, IE I call a search with size 100, I want  
to have the most recent 100 objects returned to me, how would I go about  
doing that?

I tried using sort, but it seems that it just sorts the results after the  
search completed

--  
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/e25a78e9-c126-439e-ad53-0547de3b358d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e25a78e9-c126-439e-ad53-0547de3b358d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Phil\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Phil\_Greenberg](https://discuss.elastic.co/u/Phil_Greenberg)
#### Post date: [April 17, 2014, 9:36pm UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/2 "2014-04-17T21:36:04Z")

</div>

I am also facing the same issue.

Right now, I am just doing a filter myself, but I would assume this is a  
common use case, an ES must have a way to deal with it?

On Tuesday, April 15, 2014 6:24:52 PM UTC-7, Joris Bolsens wrote:

> I am using the javascript API and want to do a search and have it search  
> through the most recent objects, IE I call a search with size 100, I want  
> to have the most recent 100 objects returned to me, how would I go about  
> doing that?
> 
> I tried using sort, but it seems that it just sorts the results after the  
> search completed

--  
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/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%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: [April 17, 2014, 9:39pm UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/3 "2014-04-17T21:39:43Z")

</div>

Filter (range filter on the date/time field) is exactly the way to do this.

Another possibility is using rolling indexes (e.g. an index per day, like  
the logstash indexes are defined) but that obviously depends on a lot of  
other business concerns and isn't really viable for most applications

--

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, Apr 18, 2014 at 12:36 AM, Phil Greenberg \<  
[philip.n.greenberg@gmail.com](mailto:philip.n.greenberg@gmail.com)\> wrote:

> I am also facing the same issue.
> 
> Right now, I am just doing a filter myself, but I would assume this is a  
> common use case, an ES must have a way to deal with it?
> 
> On Tuesday, April 15, 2014 6:24:52 PM UTC-7, Joris Bolsens wrote:
> 
> > I am using the javascript API and want to do a search and have it search  
> > through the most recent objects, IE I call a search with size 100, I want  
> > to have the most recent 100 objects returned to me, how would I go about  
> > doing that?
> > 
> > I tried using sort, but it seems that it just sorts the results after the  
> > search completed
> 
> --  
> 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/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%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/CAHTr4Zu9B78T\_aOECERuo0THM29fs%3DVXavesSC4n2P7rFRFBtA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zu9B78T_aOECERuo0THM29fs%3DVXavesSC4n2P7rFRFBtA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Phil\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Phil\_Greenberg](https://discuss.elastic.co/u/Phil_Greenberg)
#### Post date: [April 17, 2014, 9:43pm UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/4 "2014-04-17T21:43:14Z")

</div>

Thanks Itamar.

So are you saying it's not possible to ask ES for the most recent X objects  
that match the given query? Only to say give me the last 30 days of  
objects?

On Thursday, April 17, 2014 2:39:43 PM UTC-7, Itamar Syn-Hershko wrote:

> Filter (range filter on the date/time field) is exactly the way to do this.
> 
> Another possibility is using rolling indexes (e.g. an index per day, like  
> the logstash indexes are defined) but that obviously depends on a lot of  
> other business concerns and isn't really viable for most applications
> 
> --
> 
> 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, Apr 18, 2014 at 12:36 AM, Phil Greenberg \<[philip.n....@gmail.com](mailto:philip.n....@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I am also facing the same issue.
> > 
> > Right now, I am just doing a filter myself, but I would assume this is a  
> > common use case, an ES must have a way to deal with it?
> > 
> > On Tuesday, April 15, 2014 6:24:52 PM UTC-7, Joris Bolsens wrote:
> > 
> > > I am using the javascript API and want to do a search and have it search  
> > > through the most recent objects, IE I call a search with size 100, I want  
> > > to have the most recent 100 objects returned to me, how would I go about  
> > > doing that?
> > > 
> > > I tried using sort, but it seems that it just sorts the results after  
> > > the search completed
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%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/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%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: [April 17, 2014, 9:51pm UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/5 "2014-04-17T21:51:23Z")

</div>

For recent X just sort on the \_timestamp field and specify X as the page  
size

> **[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, Apr 18, 2014 at 12:43 AM, Phil Greenberg \<  
[philip.n.greenberg@gmail.com](mailto:philip.n.greenberg@gmail.com)\> wrote:

> Thanks Itamar.
> 
> So are you saying it's not possible to ask ES for the most recent X  
> objects that match the given query? Only to say give me the last 30 days  
> of objects?
> 
> On Thursday, April 17, 2014 2:39:43 PM UTC-7, Itamar Syn-Hershko wrote:
> 
> > Filter (range filter on the date/time field) is exactly the way to do  
> > this.
> > 
> > Another possibility is using rolling indexes (e.g. an index per day, like  
> > the logstash indexes are defined) but that obviously depends on a lot of  
> > other business concerns and isn't really viable for most applications
> > 
> > --
> > 
> > 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, Apr 18, 2014 at 12:36 AM, Phil Greenberg [philip.n....@gmail.com](mailto:philip.n....@gmail.com)wrote:
> > 
> > > I am also facing the same issue.
> > > 
> > > Right now, I am just doing a filter myself, but I would assume this is a  
> > > common use case, an ES must have a way to deal with it?
> > > 
> > > On Tuesday, April 15, 2014 6:24:52 PM UTC-7, Joris Bolsens wrote:
> > > 
> > > > I am using the javascript API and want to do a search and have it  
> > > > search through the most recent objects, IE I call a search with size 100, I  
> > > > want to have the most recent 100 objects returned to me, how would I go  
> > > > about doing that?
> > > > 
> > > > I tried using sort, but it seems that it just sorts the results after  
> > > > the search completed
> > > 
> > > --  
> > > 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).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%  
> > > [40googlegroups.com](http://40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%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/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%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/CAHTr4ZuNk-5HOLmbv4xutsUiGRuntUtcwEi%2BOK\_4r698ixygYQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZuNk-5HOLmbv4xutsUiGRuntUtcwEi%2BOK_4r698ixygYQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Phil\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Phil\_Greenberg](https://discuss.elastic.co/u/Phil_Greenberg)
#### Post date: [April 18, 2014, 6:19pm UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/6 "2014-04-18T18:19:34Z")

</div>

Oh, awesome, thank you so much for the help, I'll give that a try!

On Thursday, April 17, 2014 2:51:23 PM UTC-7, Itamar Syn-Hershko wrote:

> For recent X just sort on the \_timestamp field and specify X as the page  
> size  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-timestamp-field.html)
> 
> --
> 
> 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, Apr 18, 2014 at 12:43 AM, Phil Greenberg \<[philip.n....@gmail.com](mailto:philip.n....@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Thanks Itamar.
> > 
> > So are you saying it's not possible to ask ES for the most recent X  
> > objects that match the given query? Only to say give me the last 30 days  
> > of objects?
> > 
> > On Thursday, April 17, 2014 2:39:43 PM UTC-7, Itamar Syn-Hershko wrote:
> > 
> > > Filter (range filter on the date/time field) is exactly the way to do  
> > > this.
> > > 
> > > Another possibility is using rolling indexes (e.g. an index per day,  
> > > like the logstash indexes are defined) but that obviously depends on a lot  
> > > of other business concerns and isn't really viable for most applications
> > > 
> > > --
> > > 
> > > 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, Apr 18, 2014 at 12:36 AM, Phil Greenberg \<[philip.n....@gmail.com](mailto:philip.n....@gmail.com)
> > > 
> > > > wrote:
> > > 
> > > > I am also facing the same issue.
> > > > 
> > > > Right now, I am just doing a filter myself, but I would assume this is  
> > > > a common use case, an ES must have a way to deal with it?
> > > > 
> > > > On Tuesday, April 15, 2014 6:24:52 PM UTC-7, Joris Bolsens wrote:
> > > > 
> > > > > I am using the javascript API and want to do a search and have it  
> > > > > search through the most recent objects, IE I call a search with size 100, I  
> > > > > want to have the most recent 100 objects returned to me, how would I go  
> > > > > about doing that?
> > > > > 
> > > > > I tried using sort, but it seems that it just sorts the results after  
> > > > > the search completed
> > > > 
> > > > --  
> > > > 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).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%  
> > > > [40googlegroups.com](http://40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fb4a3d83-c386-459b-beb6-a8ca4fcbb286%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ec1fa45f-4534-45a2-96ae-1d5edf783ac4%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/53cdd542-4d17-47b9-bedb-3d2f6937864d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/53cdd542-4d17-47b9-bedb-3d2f6937864d%40googlegroups.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:34am UTC](https://discuss.elastic.co/t/searching-most-recent-objects/17036/7 "2017-07-06T01:34:59Z")

</div>


