# Help with this query (combine term and range)

**URL:** <https://discuss.elastic.co/t/help-with-this-query-combine-term-and-range/236431>\
**Category:** Elasticsearch\
**Created:** [June 10, 2020, 2:16am UTC](https://discuss.elastic.co/t/help-with-this-query-combine-term-and-range/236431 "2020-06-10T02:16:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![justaniceguy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justaniceguy/32/69769_2.png) [@justaniceguy](https://discuss.elastic.co/u/justaniceguy)\
**Post date:** [June 10, 2020, 2:16am UTC](https://discuss.elastic.co/t/help-with-this-query-combine-term-and-range/236431/1 "2020-06-10T02:16:09Z")

</div>

When I run this query with `range` I get results:

```auto
    {
       "query":{
          "range":{
             "crawled":{
                "lt":1591666432
             }
          },
       },
       "from":0,
       "size":1
    }

```

When I run this query with `term` I get results:

```auto
    {
       "query":{
          "term":{
             "status":{
                "value":1
             }
          }
       },
       "from":0,
       "size":1
    }

```

But when I run this query (combining `range` and `term`) I get an error message:

```auto
    {
       "query":{
          "range":{
             "crawled":{
                "lt":1591666432
             }
          },
          "term":{
             "status":{
                "value":1
             }
          }
       },
       "from":0,
       "size":1
    }

```

This is the error message:

```auto
    [range] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

```

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [June 10, 2020, 6:48am UTC](https://discuss.elastic.co/t/help-with-this-query-combine-term-and-range/236431/2 "2020-06-10T06:48:55Z")

</div>

you can combine term and range with Bool query:

```
   {
      "query": {
        "bool": {
          "must": [
            {
              "range": {
                "crawled": {
                  "lt": 1591666432
                }
              }
            },
            {
              "term": {
                "status": {
                  "value": 1
                }
              }
            }
          ]
        },
        "from": 0,
        "size": 1
      }
    }
```

---

<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 8, 2020, 6:59am UTC](https://discuss.elastic.co/t/help-with-this-query-combine-term-and-range/236431/3 "2020-07-08T06:59:52Z")

</div>

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