# Return a single document per user per hour

**URL:** https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182
**Category:** Elasticsearch
**Created:** [June 8, 2018, 5:22pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182 "2018-06-08T17:22:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![le\_John](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@le\_John](https://discuss.elastic.co/u/le_John)
#### Post date: [June 8, 2018, 5:22pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/1 "2018-06-08T17:22:45Z")

</div>

Is there a way to return a single document per hour?  
Another way to describe what I'm after: I'm thinking of a "date histogram" type scenario, but within the query, not with aggregations.

The data is basically a table with users' activity per hour (timestamp), with some values associated with their activity recorded at each hour. They can be active in more than one way (resulting in multiple documents per hour), but for this query, I'd like to simply grab a single document with information per hour, for each user. Is this possible?

Thanks

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 8, 2018, 6:10pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/2 "2018-06-08T18:10:34Z")

</div>

Which document would you grab though?

---

<div class="post-metadata">

### Author: ![le\_John](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@le\_John](https://discuss.elastic.co/u/le_John)
#### Post date: [June 8, 2018, 6:16pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/3 "2018-06-08T18:16:26Z")

</div>

In this case, it doesn't matter which document, just that I can grab a single one. Order doesn't matter, I just want to use some of the meta data in the other fields.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 8, 2018, 8:56pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/4 "2018-06-08T20:56:03Z")

</div>

What about just using a filtered query with a date range attached to it?

---

<div class="post-metadata">

### Author: ![le\_John](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@le\_John](https://discuss.elastic.co/u/le_John)
#### Post date: [June 8, 2018, 10:48pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/5 "2018-06-08T22:48:38Z")

</div>

The hour is kind of an arbitrary amount and I'm looking for something more scalable. In the future I might be looking for per minute data. I think something like top\_hits might be closer to what I'm looking for.

---

<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, 2018, 10:48pm UTC](https://discuss.elastic.co/t/return-a-single-document-per-user-per-hour/135182/6 "2018-07-06T22:48:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
