title: Reverse a match or match every element in an array where some IDs are not set
body: <p>Struggling with making this ES query. Basically, I have a nested object, something like:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
    &quot;exchangeRate&quot;: 0.01,
    &quot;payments&quot;: [
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;paymentId&quot;: &quot;some-id&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;amount&quot;: 400.0
      },
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;paymentId&quot;: &quot;some-id2&quot;,
        &quot;amount&quot;: -200.0
      },
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;amount&quot;: -200.0
      }
    ]
  }
  </code></pre>
  <p>And I want to match on an object where some of the &quot;paymentId&quot; keys are defined, but not all. So the above object would be a match. Whereas something like:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
    &quot;exchangeRate&quot;: 0.01,
    &quot;payments&quot;: [
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;paymentId&quot;: &quot;some-id&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;amount&quot;: 400.0
      },
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;paymentId&quot;: &quot;some-id2&quot;,
        &quot;amount&quot;: -200.0
      },
      {
        &quot;id&quot;: &quot;00000000-0000-0000-0000-000000000000&quot;,
        &quot;currency&quot;: &quot;USD&quot;,
        &quot;paymentId&quot;: &quot;some-id3&quot;,
        &quot;amount&quot;: -200.0
      }
  </code></pre>
  <p>Would not match.</p>
  <p>I've made a query which matches if all paymendIds are defined and returns all objects where that is true. This query is:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;must&quot;: {
          &quot;nested&quot;: {
            &quot;path&quot;: &quot;payments&quot;,
            &quot;query&quot;: {
              &quot;exists&quot;: {
                &quot;field&quot;: &quot;payments.paymendIds&quot;
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>The question would be how do I reverse this? So that if it matches this query, it doesn't return as a match. As putting &quot;must_not&quot; simply does the opposite. It returns all records that don't have any paymentIds defined at all. Which is something I want to match on, but I need all the ones that even have only <em>some</em> of the paymentIds set.</p>