title: Retrieve matched array element in Elastic Search query
body: <p>In a movie database, I store the ratings (0 to 5 stars) given by users to each of the movies. I have the following document structure indexed in Elastic Search (version 1.2.2)</p>
  
  <pre><code>"_index": "my_index"
  "_type": "film",
  "_id": "6629",
  "_source": {
    "id": "6629",
    "title": "Fight Club",
    "ratings" : [
      { "user_id" : 1234, "rating_value" : 3 },
      { "user_id" : 4567, "rating_value" : 2 },
      { "user_id" : 7890, "rating_value" : 1 }
      .....
    ]
  }
  
  "_index": "my_index"
  "_type": "film",
  "_id": "6630",
  "_source": {
    "id": "6630",
    "title": "Pulp Fiction",
    "ratings" : [
      { "user_id" : 1234, "rating_value" : 1 },
      { "user_id" : 7654, "rating_value" : 2 },
      { "user_id" : 4321, "rating_value" : 5 }
      .....
    ]
  }
  </code></pre>
  
  <p>etc ...</p>
  
  <p>My goal is to get, in a single search, all the movies rated by a user (let's say user 1234), <strong>alongside with the rating_value</strong></p>
  
  <p>If I do the following search</p>
  
  <pre><code>GET my_index/film/_search
  {
    "query": {
      "match": {
        "ratings.user_id": "1234"
      }
    }
  }
  </code></pre>
  
  <p>I get, for all matched movies, the whole document, and then, I have to parse the whole ratings array to find out which element of the array has matched my query and what is the rating_value associated with the user_id 1234.</p>
  
  <p>Ideally, I would like the result of this query to be</p>
  
  <pre><code>"hits": [ {
    "_index": "my_index"
    "_type": "film",
    "_id": "6629",
    "_source": {
      "id": "6629",
      "title": "Fight Club",
      "ratings" : [
        { "user_id" : 1234, "rating_value" : 3 }, // &lt;= only the row that matches the query
      ]
    },
    "_index": "my_index"
    "_type": "film",
    "_id": "6630",
    "_source": {
      "id": "6630",
      "title": "Pulp Fiction",
      "ratings" : [
        { "user_id" : 1234, "rating_value" : 1 },  // &lt;= only the row that matches the query
      ]
    }
  } ]
  </code></pre>
  
  <p>Thanks in advance</p>