title: Elasticsearch: how to apply multiple filters to the same value?
body: <p>Shortly: when a field has multiple values, how can I get only those items where both my filter applies to the SAME value in a multiple-values field?</p>
  
  <h2>Details</h2>
  
  <p>I have stored in Elasticsearch some items which have a nested field with multiple values, e.g.</p>
  
  <pre><code>"hits": [
      {
          "name": "John",
          "tickets": [
              {
                  "color": "green",
                  "code": "001"
              },
              {
                  "color": "red",
                  "code": "002"
              }
          ]
      },
      {
          "name": "Frank",
          "tickets": [
              {
                  "color": "red",
                  "code": "001"
              },
              {
                  "color": "green",
                  "code": "002"
              }
          ]
      }
  ]
  </code></pre>
  
  <p>Now consider these filters:</p>
  
  <pre><code>...
  filter: [
      { terms: { 'tickets.code': '001' } },
      { terms: { 'tickets.color': 'green' } },
  ]
  ...
  </code></pre>
  
  <p>Both items match, because each one of them has at least a ticket with code "001" and each one of them has ticket with color "green". </p>
  
  <p>How do I write my filters so that only the first match, because it has a ticket which has code "001" AND color "green"?</p>
  
  <p>Thank you in advance for any suggestion.</p>