title: ElasticSearch multiple AND/OR query
body: <p>I have a schema like below -</p>
  <pre><code>{
      &quot;errorCode&quot;: &quot;e015&quot;,
      &quot;errorDescription&quot;: &quot;Description e015&quot;,
      &quot;storeId&quot;: &quot;71102&quot;,
      &quot;businessFunction&quot;: &quot;PriceFeedIntegration&quot;,
      &quot;createdDate&quot;: &quot;2021-02-20T09:17:04.004&quot;,
      &quot;readBy&quot;: [
          {
              &quot;userId&quot;: &quot;scha3055&quot;
          },
      {
              &quot;userId&quot;: &quot;abcd1234&quot;
          }
  
      ]
  }
  </code></pre>
  <p>I'm trying to search combination of &quot;errorCode&quot;,&quot;storeId&quot;,&quot;businessFunction&quot; with a date range like below -</p>
  <pre><code>{
      &quot;query&quot;: {
          &quot;bool&quot;: {
              &quot;must&quot;: [
                  {
                      &quot;terms&quot;: {
                          &quot;errorCode&quot;: [
                              &quot;e015&quot;,
                              &quot;e020&quot;,
                              &quot;e022&quot;
                          ]
                      }
                  },
                  {
                      &quot;terms&quot;: {
                          &quot;storeId&quot;: [
                              &quot;71102&quot;,
                              &quot;71103&quot;
                          ]
                      }
                  },
                  
                  {
                      &quot;range&quot;: {
                          &quot;createdDate&quot;: {
                              &quot;gte&quot;: &quot;2021-02-16T09:17:04.000&quot;,
                              &quot;lte&quot;: &quot;2021-02-22T00:00:00.005&quot;
                          }
                      }
                  }
              ]
          }
      }
  }
  </code></pre>
  <p>But when I add another condition with &quot;businessFunction&quot; the query does not work.</p>
  <pre><code>{
      &quot;query&quot;: {
          &quot;bool&quot;: {
              &quot;must&quot;: [
                  {
                      &quot;terms&quot;: {
                          &quot;errorCode&quot;: [
                              &quot;e015&quot;,
                              &quot;e020&quot;,
                              &quot;e022&quot;
                          ]
                      }
                  },
                  {
                      &quot;terms&quot;: {
                          &quot;storeId&quot;: [
                              &quot;71102&quot;,
                              &quot;71103&quot;
                          ]
                      }
                  },
                  {
                      &quot;terms&quot;: {
                          &quot;errorDescription&quot;: [
                              &quot;Description e020&quot;,
                              &quot;71103&quot;
                          ]
                      }
                  },
                  {
                      &quot;range&quot;: {
                          &quot;createdDate&quot;: {
                              &quot;gte&quot;: &quot;2021-02-16T09:17:04.000&quot;,
                              &quot;lte&quot;: &quot;2021-02-22T00:00:00.005&quot;
                          }
                      }
                  }
              ]
          }
      }
  }
  </code></pre>
  <p>What am I missing in the query? When I add the third &quot;terms&quot; cndition , the query does not work. Please suggest or let me know any alternate way.</p>