title: ElasticSearch: access document nested value in groovy script
body: <p>I have a document stored in ElasticSearch as below.
  _source:</p>
  
  <pre><code> {
   "firstname": "John",
   "lastname": "Smith",
   "medals":[
             {
               "bucket": 100, 
               "count": 1
             },
             {
               "bucket": 150,
               "count": 2
             }
           ]
    }
  </code></pre>
  
  <p>I can access the string type value inside a document using <code>doc.firstname</code> for scripted metric aggregation  <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html" rel="noreferrer">http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html</a>.</p>
  
  <p>But I am not able to get the field value using <code>doc.medals[0].bucket.</code></p>
  
  <p>Can you please help me out and let me know how to access the values inside nested fields? </p>