# Terms query with the operator AND

**URL:** <https://discuss.elastic.co/t/terms-query-with-the-operator-and/88726>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 2:52pm UTC](https://discuss.elastic.co/t/terms-query-with-the-operator-and/88726 "2017-06-08T14:52:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirtash](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@Kirtash](https://discuss.elastic.co/u/Kirtash)\
**Post date:** [June 8, 2017, 2:52pm UTC](https://discuss.elastic.co/t/terms-query-with-the-operator-and/88726/1 "2017-06-08T14:52:59Z")

</div>

Hello!

I have this register (is a fragment):

"\_index": "worker",  
"\_type": "work",  
"\_id": "055-008765",  
"\_score": 1,  
"\_source": {  
"sex": "Women",  
"name": "Nat",  
"vehicles": [  
"Car",  
"Bus "  
]  
}

And I have this query:

"bool": {  
"must": [  
{  
"terms": {  
"vehicles": [  
"car",  
"bus"  
]  
}  
}  
]

I want all the workers that they have car AND bus, not one of them. How can I do it?

Thanks for all.

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [June 8, 2017, 9:18pm UTC](https://discuss.elastic.co/t/terms-query-with-the-operator-and/88726/2 "2017-06-08T21:18:50Z")

</div>

> [@Kirtash](#):
>
> How can I do it?

You can do this either with a single `match` query, or with a `bool` as you mentioned, here's an example of both:

```
POST /_search
{
  "query": {
    "match": {
      "vehicles": {
        "query": "car bus",
        "operator": "AND"
      }
    }
  }
}

POST /_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {"vehicles": "car"}},
        {"match": {"vehicles": "bus"}}
      ]
    }
  }
}

```

---

<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 6, 2017, 9:18pm UTC](https://discuss.elastic.co/t/terms-query-with-the-operator-and/88726/3 "2017-07-06T21:18:54Z")

</div>

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