title: How to do match multiple nested object in one document with inner hits in elasticsearch
body: <p>How do I write a query with two search terms which matches nested objects with inner hits highlighted.</p>
  <p>Below is the sample usecase:</p>
  <p>I have a mapping:</p>
  <pre><code>&quot;mappings&quot;: {
        &quot;properties&quot;: {
          &quot;grocery_name&quot;: {
            &quot;type&quot;: &quot;text&quot;
          },
          &quot;items&quot;: {
            &quot;type&quot;: &quot;nested&quot;,
            &quot;properties&quot;: {
              &quot;name&quot;: {
                &quot;type&quot;: &quot;text&quot;
              },
              &quot;stock&quot;: {
                &quot;type&quot;: &quot;integer&quot;
              },
              &quot;category&quot;: {
                &quot;type&quot;: &quot;text&quot;
              }
            }
          }
        }
      }
  </code></pre>
  <p>and the data looks like below</p>
  <pre><code>{
    &quot;grocery_name&quot;: &quot;Elastic Eats&quot;,
    &quot;items&quot;: [
      {
        &quot;name&quot;: &quot;Red banana&quot;,
        &quot;stock&quot;: &quot;12&quot;,
        &quot;category&quot;: &quot;fruit&quot;
      },
      {
        &quot;name&quot;: &quot;Cavendish banana&quot;,
        &quot;stock&quot;: &quot;10&quot;,
        &quot;category&quot;: &quot;fruit&quot;
      },
      {
        &quot;name&quot;: &quot;peach&quot;,
        &quot;stock&quot;: &quot;10&quot;,
        &quot;category&quot;: &quot;fruit&quot;
      },
      {
        &quot;name&quot;: &quot;carrot&quot;,
        &quot;stock&quot;: &quot;9&quot;,
        &quot;category&quot;: &quot;vegetable&quot;
      },
      {
        &quot;name&quot;: &quot;broccoli&quot;,
        &quot;stock&quot;: &quot;5&quot;,
        &quot;category&quot;: &quot;vegetable&quot;
      }
    ]
  }
  </code></pre>
  <p>here if i want a document which has <em><strong>peach</strong></em> and <em><strong>carrot</strong></em> both in nested docs
  i can do search with multiple nested queries like below</p>
  <pre><code>{
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;must&quot;: [
          {
            &quot;nested&quot;: {
              &quot;path&quot;: &quot;items&quot;,
              &quot;query&quot;: {
                &quot;match_phrase&quot;: {
                  &quot;items.name&quot;: {
                    &quot;query&quot;: &quot;carrot&quot;
                  }
                }
              }
            }
          },
          {
            &quot;nested&quot;: {
              &quot;path&quot;: &quot;items&quot;,
              &quot;query&quot;: {
                &quot;match_phrase&quot;: {
                  &quot;items.name&quot;: {
                    &quot;query&quot;: &quot;peach&quot;
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
  </code></pre>
  <p>the above query works perfectly, but if i add inner hits i can't add for both nested queries , if i do i get following error</p>
  <blockquote>
  <p>  [inner_hits] already contains an entry for key[items]</p>
  </blockquote>
  <p>i want to get each matched nested object highlighted, as <strong>_source</strong> highlighting is not supported in elasticsearch is there any way i can do highlighting for each nested object?</p>