# How to write a range query for a date field with an interval on Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-write-a-range-query-for-a-date-field-with-an-interval-on-elasticsearch/315328>\
**Category:** Elasticsearch\
**Created:** [September 28, 2022, 6:55am UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-for-a-date-field-with-an-interval-on-elasticsearch/315328 "2022-09-28T06:55:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahkam\_Naseek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahkam_naseek/32/111368_2.png) [@Ahkam\_Naseek](https://discuss.elastic.co/u/Ahkam_Naseek)\
**Post date:** [September 28, 2022, 6:55am UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-for-a-date-field-with-an-interval-on-elasticsearch/315328/1 "2022-09-28T06:55:23Z")

</div>

This is my current query which fetches documents which are older than 365 days from now.

```auto
"query": {
 "bool": {
  "must": [
    {
      "match": {
        "doc_type": "AP - ACH CHECKS"
      }
    },
    {
      "range": {
        "capture_date": {
          "lte": "now-365d"
        }
      }
    }
  ]
}

```

}

But I need to fetch the documents which are older than 365 days from the capture\_date field. So tried like below and didn't work

```auto
{
  "range": {
    "capture_date": {
      "lte": "capture_date-365d"
    }
  }
}

```

What should be the correct format?

---

<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:** [October 26, 2022, 6:55am UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-for-a-date-field-with-an-interval-on-elasticsearch/315328/2 "2022-10-26T06:55:36Z")

</div>

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