Abdul Khadar
Abdul Khadar

Reputation: 37

limiting date histogram to a date range without affecting results

I want to limit the results to a date range while performing the date histogram. But it seems to affect the results set (hits). Is there any way that I can do the same, but not affect the hits area?

Upvotes: 1

Views: 1178

Answers (1)

Vineeth Mohan
Vineeth Mohan

Reputation: 19253

Filter aggregation would be an ideal match here.

{
  "query": {
    "match": {
      "Content": "my query"
    }
  },
  "aggs": {
    "filterByDate": {
      "filter": {
        "range": {
          "<dateField>": {
            "gte": "<StartDate>",
            "lt": "<EndDate>"
              }
            }
          },
          "aggs": {
            "dateStats": {
              "date_histogram": {
                "field": "<dateField>"
              }
            }
          }
        }  
      }
    }

Upvotes: 2

Related Questions