title: Elasticsearch Nested Query with Must and Must Not with same fields
body: <p>Sample data</p>
  <pre><code>poll_A:
  {
    popular: [
      { domains: [ &quot;google.com&quot;, &quot;etsy.com&quot;, &quot;amazon.com&quot; ], rank: 1 },
      { domains: [ &quot;google.com&quot;, &quot;amazon.com&quot; ], rank: 2 },
    ]
  }
  
  poll_B:
  {
    popular: [
      { domains: [ &quot;google.com&quot;, &quot;etsy.com&quot;, &quot;amazon.com&quot; ], rank: 1 },
      { domains: [ &quot;google.com&quot;, &quot;etsy.com&quot;, &quot;amazon.com&quot; ], rank: 2 },
    ]
  }
  </code></pre>
  <p>I am trying to create a query that will check if a domain only exists in rank 1. The following query is what I started with because it seemed right. However, it seems that the match query will check across every instance of the nested field regardless of which rank I want to check against.</p>
  <pre><code>{
    &quot;query&quot;: {
      &quot;nested&quot;: {
        &quot;path&quot;: &quot;popular&quot;,
        &quot;query&quot;: {
          &quot;bool&quot;: {
            &quot;must&quot;: [
              {
                &quot;match&quot;: {
                  &quot;popular.domains&quot;: &quot;etsy.com&quot;
                }
              },
              {
                &quot;match&quot;: {
                  &quot;popular.rank&quot;: 1
                }
              }
            ],
            &quot;must_not&quot;: [
              {
                &quot;match&quot;: {
                  &quot;popular.domains&quot;: &quot;etsy.com&quot;
                }
              },
              {
                &quot;range&quot;: {
                  &quot;popular.rank&quot;: {
                    &quot;gte&quot;: 2
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
  </code></pre>
  <p>Essentially I want to check that the domain matches in rank 1 but does not match with any other rank.</p>