# DELETE documents documents that have field date1 in the given interval and the value of "date1 - date2" is greater than 1 hour

**URL:** <https://discuss.elastic.co/t/delete-documents-documents-that-have-field-date1-in-the-given-interval-and-the-value-of-date1-date2-is-greater-than-1-hour/245040>\
**Category:** Elasticsearch\
**Created:** [August 14, 2020, 3:39pm UTC](https://discuss.elastic.co/t/delete-documents-documents-that-have-field-date1-in-the-given-interval-and-the-value-of-date1-date2-is-greater-than-1-hour/245040 "2020-08-14T15:39:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rysiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rysiu/32/61919_2.png) [@Rysiu](https://discuss.elastic.co/u/Rysiu)\
**Post date:** [August 14, 2020, 3:39pm UTC](https://discuss.elastic.co/t/delete-documents-documents-that-have-field-date1-in-the-given-interval-and-the-value-of-date1-date2-is-greater-than-1-hour/245040/1 "2020-08-14T15:39:09Z")

</div>

We have a basic index with two fields: date1 and date2.

```auto
PUT your_index
{
  "mappings": {
    "your_type": {
      "properties": {
        "time1": {
          "type": "date",
        },
        "time2": {
          "type": "date",
        }
      }
    }
  }
}

```

I want to make queries that DELETE documents that have field date1 in the given interval and the value of "date1 - date2" is greater than 1 hour.

Classically, I can make a range in the date1 field to add the appropriate date range.

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "date1": {
              "gte": "2019-11-01 ",
              "lte": "2019-11-30"
            }
          }
        }
      ]
    }
  }
}

```

But how to add a second condition (logical AND between conditions)?

So how to add to the query "value of "date1 - date2" is greater than 1 hour."?

---

<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:** [September 11, 2020, 3:39pm UTC](https://discuss.elastic.co/t/delete-documents-documents-that-have-field-date1-in-the-given-interval-and-the-value-of-date1-date2-is-greater-than-1-hour/245040/2 "2020-09-11T15:39:15Z")

</div>

Closed on September 11, 2020, 3:39pm UTC

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