How to specify a date query and another query term

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:

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

Take a look at this...

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

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.

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