# Get earliest timestamp per day

**URL:** <https://discuss.elastic.co/t/get-earliest-timestamp-per-day/191722>\
**Category:** Elasticsearch\
**Created:** [July 23, 2019, 12:37am UTC](https://discuss.elastic.co/t/get-earliest-timestamp-per-day/191722 "2019-07-23T00:37:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EZprogramming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ezprogramming/32/57291_2.png) [@EZprogramming](https://discuss.elastic.co/u/EZprogramming)\
**Post date:** [July 23, 2019, 12:37am UTC](https://discuss.elastic.co/t/get-earliest-timestamp-per-day/191722/1 "2019-07-23T00:37:50Z")

</div>

I am trying to get the earliest (minimum) timestamp per day for a specfici message and log group.

However, my output is not what I'm expecting, I only get the minimum timestamp among all timestamp and not the minimum timestamp per day. How can I get the earliest timestamp for each day?

**Output:**

```
  "aggregations" : {
    "min-timestamp" : {
      "value" : 1.561659850322E12,
      "value_as_string" : "2019-06-27T18:24:10.322Z"
    }
  }

```

**Here is Elasticsearch query:**

```
GET /stage-cloudwatch/_search
{
  "aggs":{
    "min-timestamp": {
      "min": {
        "field": "@timestamp"
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        { 
          "match_phrase": {
            "message": "PROCESS - START - file_type:aux"
          }
        },
        {
          "match_phrase": {
            "cloudwatch_logs.log_group": "/aws/lambda/b2_raw_processor"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![EZprogramming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ezprogramming/32/57291_2.png) [@EZprogramming](https://discuss.elastic.co/u/EZprogramming)\
**Post date:** [July 23, 2019, 5:14pm UTC](https://discuss.elastic.co/t/get-earliest-timestamp-per-day/191722/2 "2019-07-23T17:14:53Z")

</div>

**Temporary solution:**

```
{
  "aggs":{
    "min-timestamp": {
      "min": {
        "field": "@timestamp"
      }
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "asc"
      }
    }
  ], 
  "size": 1, 
  "query": {
    "bool": {
      "must": [
        { 
          "match_phrase": {
            "message": "PROCESS - START - file_type:aux"
          }
        },
        {
          "match_phrase": {
            "cloudwatch_logs.log_group": "/aws/lambda/b2_raw_processor"
          }
        }
      ]
    }
  }
}

```

and in Kibana you have to change count in Metrics to Min on timestamp field. Then create an x axis which has a date histogram. What we basically did was finding the minimum timestamp on a given day.

[Edit]:  
If there is an Elasticsearch solution that can do this at once, please feel free to share.

---

<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:** [August 20, 2019, 5:14pm UTC](https://discuss.elastic.co/t/get-earliest-timestamp-per-day/191722/3 "2019-08-20T17:14:55Z")

</div>

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