title: Elasticsearch array only gives uniques to aggregation script
body: <p>I would like to do some simple linear algebra in Elasticsearch with a scripted metric in an aggregation. I am trying to use an array type to store a vector. My issue is that in my script, I am receiving only a set of unique values from the array, rather than the full array with its original sorting. Is there a way to get the original array in the script?</p>
  
  <p>Consider this example document:</p>
  
  <pre><code>curl -XPUT 'http://localhost:9200/arraytest/aoeu/1' -d '{
      "items": [1, 2, 2, 3]
  }'
  </code></pre>
  
  <p>It looks right in the <code>_source</code>:</p>
  
  <pre><code>curl -XGET 'http://localhost:9200/arraytest/aoeu/1'
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>{"_index":"arraytest","_type":"aoeu","_id":"1","_version":1,"found":true,"_source":{
      "items": [1, 2, 2, 3]
  }}
  </code></pre>
  
  <p>However, it does not look right when I get the value in a script:</p>
  
  <pre><code>curl -XGET 'http://localhost:9200/arraytest/aoeu/_search?pretty&amp;search_type=count' -d '{
      "query": {
          "match_all" : {}
      },
      "aggs": {
          "tails": {
              "scripted_metric": {
                  "init_script": "_agg.items = []",
                  "map_script": "_agg.items.add(doc.items)",
                  "reduce_script": "items = []; for (a in _aggs) { items.add(a.items) }; return items"
              }
          }
      }
  }'
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>{
    "took" : 103,
    "timed_out" : false,
    "_shards" : {
      "total" : 5,
      "successful" : 5,
      "failed" : 0
    },
    "hits" : {
      "total" : 1,
      "max_score" : 0.0,
      "hits" : [ ]
    },
    "aggregations" : {
      "tails" : {
        "value" : [ [ ], [ ], [ [ 1, 2, 3 ] ], [ ], [ ] ]
      }
    }
  }
  </code></pre>
  
  <p>I was expecting the result to include <code>[1, 2, 2, 3]</code>, but instead it includes <code>[1, 2, 3]</code>. I tried accessing <code>_source</code> in the map script but it said there is no such field.</p>