# Multiple query in one

**URL:** <https://discuss.elastic.co/t/multiple-query-in-one/152878>\
**Category:** Elasticsearch\
**Created:** [October 17, 2018, 4:35pm UTC](https://discuss.elastic.co/t/multiple-query-in-one/152878 "2018-10-17T16:35:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdonaire1](https://avatars.discourse-cdn.com/v4/letter/p/8baadc/32.png) [@pdonaire1](https://discuss.elastic.co/u/pdonaire1)\
**Post date:** [October 17, 2018, 4:35pm UTC](https://discuss.elastic.co/t/multiple-query-in-one/152878/1 "2018-10-17T16:35:35Z")

</div>

Hello there,

I am using ElasticSearch and I want to make a query.

I have differents modules: `['a', 'b', 'c', 'd']`.  
where `a` and `b` have an extra value (`companyId`) I need to filter the text of all modules, but I need to filter the `companyId` just for `a` and `b` not for modules `c` and `d`.

This will look something like this:

`SELECT * FROM my_table WHERE (modules in ('a', 'b') and companyId='myid') OR (modules in ('b', 'c'))`

But I have this:

```
client.search({
      index: INDEX,
      type: TYPE,
      body: {
        query: {
          bool: {
            must: {
              match: { text: 'mytext' },
            },
            filter: [
              { terms: { module: ['a', 'b', 'c', 'd'] } },
              { term: { companyId: 'myid' } },
            ]
          }
        }
      }
    });

```

Thanks a lot if you can help.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 18, 2018, 7:33am UTC](https://discuss.elastic.co/t/multiple-query-in-one/152878/2 "2018-10-18T07:33:58Z")

</div>

you can nest bool queries. so you can have a bool query, that contains of two `should` clauses (that act as an OR) and within those you can have bool queries with `must` clauses.

---

<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:** [November 15, 2018, 7:34am UTC](https://discuss.elastic.co/t/multiple-query-in-one/152878/3 "2018-11-15T07:34:00Z")

</div>

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