# Or inside must

**URL:** <https://discuss.elastic.co/t/or-inside-must/39446>\
**Category:** Elasticsearch\
**Created:** [January 18, 2016, 12:46pm UTC](https://discuss.elastic.co/t/or-inside-must/39446 "2016-01-18T12:46:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pewpewlasers](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pewpewlasers](https://discuss.elastic.co/u/pewpewlasers)\
**Post date:** [January 18, 2016, 12:46pm UTC](https://discuss.elastic.co/t/or-inside-must/39446/1 "2016-01-18T12:46:21Z")

</div>

I have a query that looks like the following

```
   functions: [...],
   query: {
       bool: {
         must: [],
         must_not: [],
         should: [],
         filter: [],
      },
   },

```

I want to limit search to when username = "demo" or isPublic = 1  
Initially I was using should for this:

```
should: [
   term: {username: "demo"},
   term: {isPublic: 1}
]

```

I quickly ran into some issues. I realized that should was simply improving scores for the results instead of restricting result? Which means entries with username = "demo" **AND** isPublic are ranked way higher. This is not what I want. I just want entries to fulfill these criteria.

A way would be to have something like `must [username: "demo" OR isPublic: 1]`, but I can't seem to find something like this in the documentation.

---

<div class="post-metadata">

**Author:** ![Daverino](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@Daverino](https://discuss.elastic.co/u/Daverino)\
**Post date:** [January 18, 2016, 4:47pm UTC](https://discuss.elastic.co/t/or-inside-must/39446/2 "2016-01-18T16:47:44Z")

</div>

If you're not interested in the scoring, you should use a filter context instead of a query context. This should give you the yes-or-no answer you're looking for. What version of ES are you using? The format for filter vs query changed significantly between 1.7 and 2.x.

Regarding the logic, yes it seems you need a nested boolean here. So something like:

```
 '{"query" : {
    "bool": {
      "filter" : [
        {
          "bool" : {
             "should" : [
               {"term" : {"username" : "demo"}}, 
               {"term" : {"isPublic" : "1"}}
             ]
          }
        }
      ]
    }
  }
}'

```

That's the 2.x syntax and honestly I'm still on 1.7. I'm eyeballing it, so please test it yourself.

---

<div class="post-metadata">

**Author:** ![pewpewlasers](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pewpewlasers](https://discuss.elastic.co/u/pewpewlasers)\
**Post date:** [January 19, 2016, 9:15am UTC](https://discuss.elastic.co/t/or-inside-must/39446/3 "2016-01-19T09:15:25Z")

</div>

Yes this works! thanks!

---

<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 5, 2017, 11:23pm UTC](https://discuss.elastic.co/t/or-inside-must/39446/4 "2017-07-05T23:23:33Z")

</div>


