Date between two indexed fields


(Marembo Ochieng') #1

I would like to retrieve a document, that has two fields for date "startDate" and "endDate", such that a given date "date" is between the document's "startDate" and "endDate".

I can't seem to formulate the range query to give me this scenario, or probably i am using the wrong query here.

Lets say we have the document as:

{
   "startDate": "2016-01-01T00:00:00",
   "endDate": "2016-12-31T23:59:59"
}

I would like this document to be matched, only if a given date is between the two values.


(Marembo Ochieng') #2

Actually this was a simple thing to do:

queryBuilder.lessThanOrEqualTo("startDate", thisMonth);
queryBuilder.greaterThanOrEqualTo("endDate", thisMonth);

(Wanglifengwf) #3
  • 1,you can use the script filter

  • 2,you can also use bool query

"query":{
  "must":{
    {"ranger":{}},
    {"ranger":{}}
  }
}

(system) #4