title: Elasticsearch Add additional condition if type is different
body: <pre><code>GET test/_search
  {
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;minimum_should_match&quot;: 1,
        &quot;should&quot;: [
          {
            &quot;bool&quot;: {
              &quot;must&quot;: [
                {
                  &quot;term&quot;: {
                    &quot;fragmentId&quot;: &quot;1&quot;
                  }
                },
                {
                  &quot;term&quot;: {
                    &quot;type&quot;: &quot;fragment&quot;
                  }
                }
              ]
            }
          },
          {
            &quot;bool&quot;: {
              &quot;must&quot;: [
                {
                  &quot;term&quot;: {
                    &quot;fragmentId&quot;: &quot;1&quot;
                  }
                },
                {
                  &quot;term&quot;: {
                    &quot;type&quot;: &quot;cf&quot;
                  }
                },
                {
                  &quot;range&quot; :{
                    &quot;start&quot;: {
                      &quot;gte&quot;: 1,
                      &quot;lte&quot;: 5
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
  </code></pre>
  <p>I am looking for two documents, one which has fragment id = 1, and type = fragment, whereas another where fragment id = 1, type = &quot;cf&quot; and start between 1 and 5.
  The above query is doing the job, but I need to write type and fragment id twice. Is there a way I can add range condition only when the type is cf, basically clubbing both bools in one ?</p>