title: Elasticsearch query match multiple values to single field
body: <p>Trying to get documents matching values <code>X1</code> or <code>Y1</code> for field <code>ABC</code>. Tried both <code>must</code> or <code>should</code> queries, but not getting expected result. Can someone suggest what kind of query should I try? Using <code>HighLevelRestClient</code>.</p>
  <pre><code>{
    &quot;bool&quot; : {
      &quot;must&quot; : [
        {
          &quot;term&quot; : {
            &quot;ABC&quot; : {
              &quot;value&quot; : &quot;X1&quot;,
              &quot;boost&quot; : 1.0
            }
          }
        },
        {
          &quot;term&quot; : {
            &quot;ABC&quot; : {
              &quot;value&quot; : &quot;Y1&quot;,
              &quot;boost&quot; : 1.0
            }
          }
        }
      ]
    }
  }
  </code></pre>
  <p>OR</p>
  <pre><code>{
    &quot;bool&quot; : {
      &quot;should&quot; : [
        {
          &quot;term&quot; : {
            &quot;ABC&quot; : {
              &quot;value&quot; : &quot;X1&quot;,
              &quot;boost&quot; : 1.0
            }
          }
        },
        {
          &quot;term&quot; : {
            &quot;ABC&quot; : {
              &quot;value&quot; : &quot;Y1&quot;,
              &quot;boost&quot; : 1.0
            }
          }
        }
      ]
    }
  }
  </code></pre>
  <p>Mapping</p>
  <pre><code>
  {
    &quot;mappings&quot;: {
      &quot;properties&quot;: {
        &quot;ABC&quot;: {
          &quot;type&quot;: &quot;text&quot;,
          &quot;fields&quot;: {
            &quot;keyword&quot;: {
              &quot;type&quot;: &quot;keyword&quot;,
              &quot;ignore_above&quot;: 2
            }
          }
        },
  
  
  </code></pre>
  <p><code>mustNot</code> condition works fine. If I just reverse the condition and ignore fields values then I get the result.</p>
  <p>X1 and Y1 are exact field values (Think enums)</p>
  <pre><code>BoolQueryBuilder x = QueryBuilders.boolQuery();
  for (SomeEnum enum : enums) { 
     x.should(QueryBuilders.termQuery(&quot;ABC&quot;,enum.name());
  }
  </code></pre>
  <p>Still query returns all documents. This should have filtered the documents to matching values</p>
  <p>Sample Doc</p>
  <pre><code>
  {
    &quot;_index&quot;: &quot;some_index&quot;,
    &quot;_type&quot;: &quot;_doc&quot;,
    &quot;_id&quot;: &quot;uyeuyeuryweoyqweo&quot;,
    &quot;_score&quot;: 1.0,
    &quot;_source&quot;: {
      &quot;A&quot;: true
      &quot;ABC&quot;: &quot;X1&quot;
      &quot;WS&quot;: &quot;E&quot;
    }
  }, 
  {
    &quot;_index&quot; : &quot;some_index&quot;,
    &quot;_type&quot; : &quot;_doc&quot;,
    &quot;_id&quot; : &quot;uyeuyeuryweoyqweo1&quot;,
    &quot;_score&quot; : 1.0,
    &quot;_source&quot; : {
      &quot;A&quot; : true,
      &quot;ABC&quot; : &quot;Y1&quot;,
      &quot;WS&quot; : &quot;MMM&quot;
    }
  }
  
  
  </code></pre>