Aviran
Aviran

Reputation: 5468

select time range using two fields

A time range is being defined by start_date and end_date and I'm trying to get all the documents that a given date, 03/27/2019 in this case, is inside the time range.

GET users/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "start_date": {
              "lte": "03/27/2019"
            }
          }
        },
        {
          "range": {
            "end_date": {
              "gte": "03/27/2019"
            }
          }
        },
        {
          "terms": {
            "locations": [
              "all"
            ]
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "gender": "male"
          }
        }
      ]
    }
  }
}

The query does not yield the proper documents, for example a document with the following values:

  "start_date": "11/25/2018"
  "end_date": "12/25/2019"

Isn't returned

Mapping of fields:

"start_date": {
            "type": "date",
            "format": "MM/DD/yyyy"
          },
"end_date": {
            "type": "date",
            "format": "MM/DD/yyyy"
          },

Upvotes: 0

Views: 35

Answers (1)

Val
Val

Reputation: 217334

I think your date format is wrong.

It should be MM/dd/yyyy instead of MM/DD/yyyy

Upvotes: 1

Related Questions