# How to combine Terms and Match query

**URL:** <https://discuss.elastic.co/t/how-to-combine-terms-and-match-query/239591>\
**Category:** Elasticsearch\
**Created:** [July 2, 2020, 8:23am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-match-query/239591 "2020-07-02T08:23:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [July 2, 2020, 8:23am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-match-query/239591/1 "2020-07-02T08:23:19Z")

</div>

Hi,  
is there a way to combine a term and a match query? I have data with categorys A,B,C,D... which contains extra field which can vary.

```auto
_source:
category: A
value: 3

_source:
category: A
value:2

_source:
category: A
value: 3
....

```

I want a query that finds all documents with the category A &B and value 3. My idea was:

```auto
{
    "query" : {
        "terms" : {
            "category":["A","B"]
        },
        "match" : {
            "message" : {
                "value": "3"
            }
        }
    }
}

```

but I get the error: `"[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]"`

**My question:** Can I combine Terms and Match querys? If so: How?

Thanks,  
defalt

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 2, 2020, 9:22am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-match-query/239591/2 "2020-07-02T09:22:53Z")

</div>

The [bool](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) query is used to combine multiple child query clauses, with the appropriate Boolean logic

---

<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 30, 2020, 9:26am UTC](https://discuss.elastic.co/t/how-to-combine-terms-and-match-query/239591/3 "2020-07-30T09:26:35Z")

</div>

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