# Elasticsearch query to classify new/recurring instances

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-to-classify-new-recurring-instances/161575>\
**Category:** Elasticsearch\
**Created:** [December 19, 2018, 5:58pm UTC](https://discuss.elastic.co/t/elasticsearch-query-to-classify-new-recurring-instances/161575 "2018-12-19T17:58:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbking](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bbking/32/77563_2.png) [@bbking](https://discuss.elastic.co/u/bbking)\
**Post date:** [December 19, 2018, 5:58pm UTC](https://discuss.elastic.co/t/elasticsearch-query-to-classify-new-recurring-instances/161575/1 "2018-12-19T17:58:00Z")

</div>

I'm trying to write a custom filter in Kibana Discover tab using ES Query DSL. I want to classify instances within a particular time period. Assume each document has following fields, I want to find all instances between 2018/12/18 to 2018/12/19 such that its hash doesn't exist before 2018/12/18. I will classify those instances as new instances. I think I will need to do an aggregation to get the timestamp of the first/oldest document that has a particular hash and do a comparison on the timestamp. Is it possible to achieve in the Kibana custom filter? How should I properly write the ES query?

I think if each document can store the timestamp of the oldest/first document temporarily, then we can do a comparison between oldest\_timestamp and its timestamp.

Not sure what kinda of query I should use to classify those instances. Any suggestions will be a great help! Thanks!

```
doc_ID: 123
hash: abchd (not unique)
timestamp: 2018/12/18
```

---

<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:** [January 16, 2019, 5:58pm UTC](https://discuss.elastic.co/t/elasticsearch-query-to-classify-new-recurring-instances/161575/2 "2019-01-16T17:58:01Z")

</div>

Closed on January 16, 2019, 5:58pm UTC

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