OpenSearch/ElasticSearch Query: Finding the date range of an index

A quick query to get the max and min timestamp values of an index:

#Find the date range of records within an index
curl -X GET "https://opensearch.example.com:9200/INDEX_NAME/_search" -H 'Content-Type: application/json' -d'
{
  "size": 0,
  "aggs": {
    "oldest_timestamp": {
      "min": {
        "field": "@timestamp"
      }
    },
    "newest_timestamp": {
      "max": {
        "field": "@timestamp"
      }
    }
  }
}'

Leave a Reply

Your email address will not be published. Required fields are marked *