# How to specify a date query and another query term

**URL:** <https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [April 8, 2022, 3:52pm UTC](https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986 "2022-04-08T15:52:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 8, 2022, 3:52pm UTC](https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986/1 "2022-04-08T15:52:20Z")

</div>

Hello - I have an index with a single date field with **n** text fields. I am trying to construct a query which will search the index for a given date range while considering the value the user supplies across all the other fields. So far, I have this:

```auto
GET /my_index/_search
{
  "query" : {
       "range" : {
          "my_date" : {
             "gte" : "10/01/2021",
             "lte" : "10/31/2021"
            }
          }
        }
}

```

But I would like to have another field, say **my\_field** , as part of the search. The reason for this is that I want to find all documents with this keyword, constrained by a date range. I tried adding a term query but that resulted in an Elasticsearch error.

Thanks in advance to all who respond.  
Kevin

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [April 8, 2022, 9:38pm UTC](https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986/2 "2022-04-08T21:38:14Z")

</div>

Take a look at this...

> **[Query and filter context | Elasticsearch Guide \[8.1\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html)**

```auto
GET /my-index/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "my-field": "my-field"
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "2022-04-07",
              "lte": "2022-04-08"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![MrFantastic2022](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MrFantastic2022](https://discuss.elastic.co/u/MrFantastic2022)\
**Post date:** [April 11, 2022, 1:34pm UTC](https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986/3 "2022-04-11T13:34:15Z")

</div>

Thanks, I'll give that a try. Appreciate the quick response. If it works, then I will have to figure out how to convert it to Java code.

---

<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:** [May 9, 2022, 1:34pm UTC](https://discuss.elastic.co/t/how-to-specify-a-date-query-and-another-query-term/301986/4 "2022-05-09T13:34:53Z")

</div>

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