title: Scripted Metric Aggregation order
body: <p>In elasticsearch 1.5.0, I try to sort/order the aggregation bucket using scripted_metric result,but receive bellow error:</p>
  
  <p>AggregationExecutionException[Invalid terms aggregation order path [custom_script]. Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end</p>
  
  <p>is any way to solve this issue?</p>
  
  <p><strong>my query like this:</strong></p>
  
  <pre><code>"aggs": {
      "mygroup": {
        "terms": {
          "field": "customername",
          "order": {
            "custom_script": "asc"
          }
        },
        "aggs": {
          "custom_script": {
            "scripted_metric": {
              ...
            }
          }
        }
      }
    }
  </code></pre>