2016-06-13 842 views
0

I指數這2個文件:Elasticsearch排序方面通過管道bucket_script聚集

POST my_index/my_type/1 
{ 
    "name": "Nephi", 
    "x": 5 
} 

POST my_index/my_type/2 
{ 
    "name": "Lehi", 
    "x": 10 
} 

這裏是我的搜索請求:

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" 
       } 
      } 
     } 
     } 
    } 
} 

我得到這樣的錯誤:

無效term-aggregator訂單路徑[the_script_bucket]。未知聚集[the_script_bucket]

但是當我改變the_script_bucket到另一個聚集像the_sumthe_avg它工作正常。我確信這是因爲the_script_bucket是一個流水線聚合,但我想根據the_script_bucket對條款進行排序,因此我可以(例如)查看100,000個文檔的前10個值。那可能嗎?

回答

0

更新:這是絕對不可能的,性能問題。

問題已關閉,原因如下:

我們只有增加新功能Elasticsearch這是橫向擴展。無論我們添加什麼東西,當您在筆記本電腦上運行50GB數據或1000個數據服務器節點並使用50 PB數據時,都可以運行。

從所有分片中提取所有項不會水平縮放,因此我們不會添加它。

https://github.com/elastic/elasticsearch/issues/8486#issuecomment-265496605

你必須這樣做,在客戶端:抓取所有的桶(這意味着你應該事先知道會是多少項目恢復),然後自己進行排序。我知道,完全適得其反。祝你好運。