# Can I use Elasticsearch to save time-based events and get the intervals between them?

**URL:** <https://discuss.elastic.co/t/can-i-use-elasticsearch-to-save-time-based-events-and-get-the-intervals-between-them/232378>\
**Category:** Elasticsearch\
**Created:** [May 13, 2020, 7:20am UTC](https://discuss.elastic.co/t/can-i-use-elasticsearch-to-save-time-based-events-and-get-the-intervals-between-them/232378 "2020-05-13T07:20:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabipetrovay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabipetrovay/32/68213_2.png) [@gabipetrovay](https://discuss.elastic.co/u/gabipetrovay)\
**Post date:** [May 13, 2020, 7:20am UTC](https://discuss.elastic.co/t/can-i-use-elasticsearch-to-save-time-based-events-and-get-the-intervals-between-them/232378/1 "2020-05-13T07:20:55Z")

</div>

I am receiving time-based events like the following:

In March I get:

```auto
{
    "id": "e0efc334-eeb5-4740-b983-e2e8f78d8c39",
    "timestamp": "2020-03-20T05:30:00Z",
    "state": "UP",
    "service": {
        "id": "7704b2b1-02d8-4b7c-9578-667e9ceb46a2",
        "name": "service1"
    }
}

```

In May I get:

```auto
{
    "id": "2990fa46-77c9-4d98-a395-86561c8c07ca",
    "timestamp": "2020-05-10T04:30:00Z",
    "state": "DOWN",
    "service": {
        "id": "7704b2b1-02d8-4b7c-9578-667e9ceb46a2",
        "name": "service1"
    }
}

```

Can I use ES to query/aggregate the event index such that I get answers to some of the following questions:

1. What is the state of `service1` now? Or at any point in time?
2. What are the intervals in which `service1` was `UP`?
3. Can I use the `date_histogram` and `calendar_interval` aggregation that interpolates the data for the intervals missing events? (e.g. the month 2020-04 does not have any events, hence it is assumed to be the latest event received before 2020-04, which is the `2020-03-20T05:30:00Z` event)

---

<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:** [May 13, 2020, 8:32am UTC](https://discuss.elastic.co/t/can-i-use-elasticsearch-to-save-time-based-events-and-get-the-intervals-between-them/232378/2 "2020-05-13T08:32:22Z")

</div>

You should be able to use [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/transform-apis.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/transform-apis.html) (and [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/transforms.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/transforms.html)) for this. It's store the data into another index though.

---

<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:** [June 10, 2020, 8:32am UTC](https://discuss.elastic.co/t/can-i-use-elasticsearch-to-save-time-based-events-and-get-the-intervals-between-them/232378/3 "2020-06-10T08:32:26Z")

</div>

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