title: Elasticsearch sort terms by pipeline bucket_script aggregation
body: <p>I index these 2 docs:</p>
  
  <pre><code>POST my_index/my_type/1
  {
      "name": "Nephi",
      "x": 5
  }
  
  POST my_index/my_type/2
  {
      "name": "Lehi",
      "x": 10
  }
  </code></pre>
  
  <p>Here is my search request:</p>
  
  <pre><code>POST my_index/my_type/_search?size=0
  {
     "aggs": {
        "some_terms_agg": {
           "terms": {
              "field": "name",
              "order": {
                 "the_script_bucket": "asc"
              }
           },
           "aggs": {
              "the_sum": {
                 "sum": {
                    "field": "x"
                 }
              },
              "the_avg": {
                 "avg": {
                    "field": "x"
                 }
              },
              "the_script_bucket": {
                 "bucket_script": {
                    "buckets_path": {
                       "a": "the_sum.value",
                       "b": "the_avg.value"
                    },
                    "script": "a + b"
                 }
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>I get an error like this: </p>
  
  <blockquote>
    <p>Invalid term-aggregator order path [the_script_bucket]. Unknown aggregation [the_script_bucket]</p>
  </blockquote>
  
  <p>But when I change <code>the_script_bucket</code> to another aggregation like <code>the_sum</code> or <code>the_avg</code> it works fine.  I'm sure this is because <code>the_script_bucket</code> is a pipeline aggregation, but I want the terms to be sorted based on <code>the_script_bucket</code> so I could (for example) see the top 10 values for 100,000 docs.  Is that possible?</p>