title: Cannot access doc['field'].value in ElasticSearch aggregation script
body: <p>With the following query:</p>
  
  <pre><code>{
    "query": {
      "filtered": {
        "filter": [],
        "query": {
          "bool": {
            "must": [
              {
                "query_string": {
                  "fields": [
                    "title"
                  ],
                  "query": "test"
                }
              }
            ]
          }
        }
      }
    },
    "aggs": {
      "my_field": {
        "terms": {
          "field": "my_field.name.raw",
          "script": "doc['title'].value"
        }
      }
    }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>QueryPhaseExecutionException[[index_name][2]: query[title:test],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: PropertyAccessException[[Error: doc['title'].value: null] [Near : {... doc['title'].value ....}] ^ [Line: 1, Column: 1]]; nested: InvocationTargetException; nested: ArrayIndexOutOfBoundsException;</p>
  </blockquote>
  
  <p>I also try using <code>_source.title</code>, <code>doc.get('title').value</code>, and other combinations of the <code>doc['field']</code> syntax - none are working for me. Is there a special nuance for using <code>script</code> within an aggregation? Am I missing something obvious?</p>
  
  <p>This fails on both ES 1.1.1 and 1.2.0.</p>