# How can I use aggregations to query distinct values across all time grouped by first seen

**URL:** https://discuss.elastic.co/t/how-can-i-use-aggregations-to-query-distinct-values-across-all-time-grouped-by-first-seen/25482
**Category:** Elasticsearch
**Created:** [July 13, 2015, 8:41pm UTC](https://discuss.elastic.co/t/how-can-i-use-aggregations-to-query-distinct-values-across-all-time-grouped-by-first-seen/25482 "2015-07-13T20:41:30Z")
**Posts on this page:** 1
**Showing post:** 16

<div class="post-metadata">

### Author: ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://discuss.elastic.co/u/simon)
#### Post date: [September 25, 2015, 8:25am UTC](https://discuss.elastic.co/t/how-can-i-use-aggregations-to-query-distinct-values-across-all-time-grouped-by-first-seen/25482/16 "2015-09-25T08:25:25Z")

</div>

> [@Mark\_Harwood](#):
>
> if numDocsProcessed % 10000 == 0:  
> elapsedSecs = int(time.time() - start)  
> dps = numDocsProcessed/elapsedSecs

@Mark_Harwood Just come across a bug in this script. If data is processed in less than 1 second the script throws a division by zero error. It is an edge case but simple to defend against.

```
if numDocsProcessed % 10000 == 0:
		elapsedSecs = int(time.time() - start)
                if elapsedSecs == 0:
                           elapsedSecs = 1
		dps = numDocsProcessed/elapsedSecs

```

---

_[View the full topic](https://discuss.elastic.co/t/how-can-i-use-aggregations-to-query-distinct-values-across-all-time-grouped-by-first-seen/25482)._
