Count field value by date range

Hi,

Is it possible to have a count of data of a specific field for the past 7 days?

Query:

GET /my-index/_count?q=my-field:*

Results:

{
"count" : 438,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
}
}

The above query is showing results for all dates.

Solution found. Hope it manages to help someone out:

GET /my-index/_search
{
  "query": {
    "bool" : {
      "must" : {
        "wildcard" : {  "my-field": "*" }
      },
     "filter": 
        {
          "range": {
            "@timestamp": {
               "gte": "now-7d",
               "lte": "now"
            }
          }
        }
    }
  }
}
1 Like

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