Multiple query in one

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.

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.

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