# Date between two indexed fields

**URL:** https://discuss.elastic.co/t/date-between-two-indexed-fields/62995
**Category:** Elasticsearch
**Created:** [October 13, 2016, 8:43pm UTC](https://discuss.elastic.co/t/date-between-two-indexed-fields/62995 "2016-10-13T20:43:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![marembo\_ochieng](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@marembo\_ochieng](https://discuss.elastic.co/u/marembo_ochieng)
#### Post date: [October 13, 2016, 8:43pm UTC](https://discuss.elastic.co/t/date-between-two-indexed-fields/62995/1 "2016-10-13T20:43:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![marembo\_ochieng](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@marembo\_ochieng](https://discuss.elastic.co/u/marembo_ochieng)
#### Post date: [October 13, 2016, 8:52pm UTC](https://discuss.elastic.co/t/date-between-two-indexed-fields/62995/2 "2016-10-13T20:52:53Z")

</div>

Actually this was a simple thing to do:

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

---

<div class="post-metadata">

### Author: ![wanglifengwf](https://avatars.discourse-cdn.com/v4/letter/w/41988e/32.png) [@wanglifengwf](https://discuss.elastic.co/u/wanglifengwf)
#### Post date: [October 14, 2016, 8:42am UTC](https://discuss.elastic.co/t/date-between-two-indexed-fields/62995/3 "2016-10-14T08:42:58Z")

</div>

- 1,you can use the script filter

- 2,you can also use bool query

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

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:12pm UTC](https://discuss.elastic.co/t/date-between-two-indexed-fields/62995/4 "2017-07-05T22:12:22Z")

</div>


