# And vs or terms?

**URL:** <https://discuss.elastic.co/t/and-vs-or-terms/79793>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 6:39pm UTC](https://discuss.elastic.co/t/and-vs-or-terms/79793 "2017-03-23T18:39:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coogle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coogle/32/15175_2.png) [@coogle](https://discuss.elastic.co/u/coogle)\
**Post date:** [March 23, 2017, 6:39pm UTC](https://discuss.elastic.co/t/and-vs-or-terms/79793/1 "2017-03-23T18:39:21Z")

</div>

Hello,

I have a question about using a terms query while specifying an array of potential values. It seems to me the query uses a boolean or to match and I would like it to use a boolean AND... for example, consider this query fragment:

```auto
...
                                    "bool": {
                                        "must": [
                                            {
                                                "nested": {
                                                    "path": "document.section",
                                                    "query": {
                                                        "terms": {
                                                            "document.section.flags": [
                                                                "full-time",
                                                                "settlement-summary"
                                                            ]
                                                        }
                                                    }
                                                }
                                            },
...

```

When I execute this query, I end up getting results that have _just_ `full-time` instead of getting only results that have `full-time` and `settlement-summary`. I've been googling around and can't seem to find a way to change that behavior?

Regards,

John

---

<div class="post-metadata">

**Author:** ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)\
**Post date:** [March 23, 2017, 9:11pm UTC](https://discuss.elastic.co/t/and-vs-or-terms/79793/2 "2017-03-23T21:11:12Z")

</div>

Looking at what you're trying to do, I think what you want to do is use the [`bool`](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-bool-query.html) query and then use a `must` clause there. I also think you really want the must clauses to be a [`term`](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-term-query.html) query rather than a [`terms`](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-term-query.html) query from what I see here.

---

<div class="post-metadata">

**Author:** ![coogle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/coogle/32/15175_2.png) [@coogle](https://discuss.elastic.co/u/coogle)\
**Post date:** [March 23, 2017, 10:04pm UTC](https://discuss.elastic.co/t/and-vs-or-terms/79793/3 "2017-03-23T22:04:38Z")

</div>

I'll try adding the bool must, but based on what I was reading why would I want to use a collection of 'term' instead of just an array of terms? Without dumping the (large) mapping, basically this particular field is a comma-separated list of flags (and those flags are parsed by ES)

John

---

<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:** [April 20, 2017, 10:04pm UTC](https://discuss.elastic.co/t/and-vs-or-terms/79793/4 "2017-04-20T22:04:41Z")

</div>

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