一個看似很瑣碎的問題,促使我今天又勤奮地閱讀了 Elasticsearch 檔案。但是,到目前為止,我還沒有遇到解決方案....
問題:
有沒有一種簡單的方法來設定過濾器聚合的 doc_count 與總 doc_count 的關系?
這是我的 search-request-json 中的一個片段。
在feature_occurrences聚合中,我過濾了檔案。
現在我想計算每個時間段中過濾/所有檔案的比率。
GET my_index/_search
{
"aggs": {
"time_buckets": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d",
"min_doc_count": 0
},
"aggs": {
"feature_occurrences": {
"filter": {
"term": {
"x": "y"
}
}
},
"feature_occurrences_per_doc" : {
// feature_occurences.doc_count / doc_count
}
有任何想法嗎 ?
uj5u.com熱心網友回復:
您可以使用 bucket_script 來計算比率:
{
"aggs": {
"date": {
"date_histogram": {
"field": "@timestamp",
"interval": "hour"
},
"aggs": {
"feature_occurrences": {
"filter": {
"term": {
"cloud.region": "westeurope"
}
}
},
"ratio": {
"bucket_script": {
"buckets_path": {
"doc_count": "_count",
"features_count": "feature_occurrences._count"
},
"script": "params.features_count / params.doc_count"
}
}
}
}
}
}
彈性桶腳本檔案:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/414395.html
標籤:
