1

我面臨的一個問題,而試圖在ES JSON請求腳本Elasticsearch 2.1 |沒有這樣的屬性:DOC

內執行腳本的請求:

POST _search 
{ 
    "query": { 
     "bool": { 
     "must": [ 
      { 
       "match_all": {} 
      } 
     ] 
     } 
    }, 
    "aggs": { 
     "bucket_histogram": { 
     "histogram": { 
      "field": "dayTime", 
      "interval": 10 
     }, 
     "aggs": { 
      "get_average": { 
       "avg": { 
        "field": "value" 
       } 
      }, 
      "check-threshold": { 
       "bucket_script": { 
        "buckets_path": { 
        "averageValue": "get_average" 
        }, 
        "script": "averageValue - doc[\"thresholdValue\"].value" 
       } 
      } 
     } 
     } 
    } 
} 

但我得到這個錯誤,而不是返回值

{ 
    "error": { 
     "root_cause": [], 
     "type": "reduce_search_phase_exception", 
     "reason": "[reduce] ", 
     "phase": "fetch", 
     "grouped": true, 
     "failed_shards": [], 
     "caused_by": { 
     "type": "groovy_script_execution_exception", 
     "reason": "failed to run inline script [averageValue - doc[\"thresholdValue\"].value] using lang [groovy]", 
     "caused_by": { 
      "type": "missing_property_exception", 
      "reason": "No such property: doc for class: 7dcca7d142ac809a7192625d43d95bde9883c434" 
     } 
     } 
    }, 
    "status": 503 
} 

然而,如果我刪除doc [\「thresholdValue \」]並輸入一個數字,一切工作正常。

回答

2

您正在使用的是bucket_script,它是Elasticsearch 2.0發佈的pipeline aggregations的一部分。管道聚合對其他聚合而不是文檔起作用,這就是爲什麼doc上下文未提供給聚合的原因。

如果要針對特定​​文檔處理聚合,則可能需要使用scripted metric aggregation

+0

非常感謝您的回答。 我希望能在java中實現這個功能,但是我找不到任何有關bucket腳本java api的文檔。 你碰巧有什麼有用的鏈接? –

+0

下面是[聚合的Java API文檔](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_structuring_aggregations.html)。它不顯示管道,但結構相同。 – pickypg

相關問題