title: minimum_number_should_match with nested must bool
body: <p>I have some documents in elasticsearch that have a list of key-value pairs. Here are some examples.</p>
  
  <pre><code>document 1:
  {
      data: [
          {
              key: key1,
              value: value1
          },
          {
              key: key1,
              value: value2
          },
      ]
  }
  
  document 2:
  {
      data: [
          {
              key: key2,
              value: blah
          },
          {
              key: key1,
              value: value2
          },
      ]
  }
  
  document 3:
  {
      data: [
          {
              key: key1,
              value: value3
          },
          {
              key: key1,
              value: value2
          },
          {
              key: key1,
              value: somevalue
          }
      ]
  }
  
  document 4:
  {
      data: [
          {
              key: key3,
              value: blah
          }
      ]
  }
  </code></pre>
  
  <p>Now I want all document that have <strong>at least 2</strong> of the values <code>[value1, value2, value3]</code> with key <code>key1</code>.
  So from the example, I need documents <strong>1 and 3</strong> but <strong>not 2 or 4</strong>.</p>
  
  <p>So far my query looks like this:</p>
  
  <pre><code>"query": {
      "nested": {
          "path": "data",
          "query": {
              "bool": {
                  "should": [
                      {
                          "bool": {
                              "must": [
                                  {
                                      "term": {
                                          "key": key1
                                      }
                                  },
                                  {
                                      "term": {
                                          "value": {
                                              "value": "value1",
                                          }
                                      }
                                  }
                              ]
                          }
                      },
                      {
                          "bool": {
                              "must": [
                                  {
                                      "term": {
                                          "key": key1
                                      }
                                  },
                                  {
                                      "term": {
                                          "value": {
                                              "value": "value2",
                                          }
                                      }
                                  }
                              ]
                          }
                      },
                      {
                          "bool": {
                              "must": [
                                  {
                                      "term": {
                                          "key": key1
                                      }
                                  },
                                  {
                                      "term": {
                                          "value": {
                                              "value": "value3",
                                          }
                                      }
                                  }
                              ]
                          }
                      }
                  ],
                  "minimum_number_should_match": 2
              }
          }
      }
  }
  </code></pre>
  
  <p>But it doesn't return any matches at all. 
  From what I understand, <code>minimum_number_should_match</code> just ensures that a document will only be returned if it matches at least the given minimum <code>should</code> occurences in the <code>bool query</code>.</p>
  
  <ul>
  <li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html" rel="nofollow">Minimum Should Match Documentation</a></li>
  <li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html" rel="nofollow">Bool Query Documentation</a></li>
  </ul>
  
  <p>But it seems like I don't fully understand how it works.
  How exactly do I get <code>minimum_number_should_match</code> to work with a nested bool query, or is there another way to do this?</p>