お世話になります。質問させていただきます。
現在、aggsで出力された中央値を条件に使おうとしています。
サンプルクエリでは、中央値の出力までは出来ていますが、計算に使おうとすると、
"type": "aggregation_execution_exception",
"reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Object[]] at aggregation [10day]"
となります。
percentilesではなく、sumも試してみましたが、このエラーメッセージに変化はありませんでした。
そこで
・このエラーはなぜ起きているのか
・Objectが何なのか調べる方法はあるか
という質問となります。
ご協力いただけますと幸いです。
request
{
"size": 0,
"aggs": {
"category": {
"terms": {
"field": "category_id",
"size": 1
},
"aggs": {
"10day": {
"date_range": {
"field": "end_at",
"format": "yyyy-MM-dd HH:mm:ss",
"ranges": [
{
"from": "now-10d",
"to": "now"
}
]
},
"aggs": {
"median_price": {
"percentiles": {
"field": "end_price",
"percents": [
50
]
}
}
}
},
"30day": {
"date_range": {
"field": "end_at",
"format": "yyyy-MM-dd HH:mm:ss",
"ranges": [
{
"from": "now-30d",
"to": "now"
}
]
},
"aggs": {
"median_price": {
"percentiles": {
"field": "end_price",
"percents": [
50
]
}
}
}
},
"calculation": {
"bucket_script": {
"buckets_path": {
"a": "10day>median_price[50.0]",
"b": "30day>median_price[50.0]"
},
"script": "params.a / params.b"
}
},
"return_filter": {
"bucket_selector": {
"buckets_path": {
"increase_ratio": "calculation"
},
"script": "params.increase_ratio <= 1.3"
}
}
}
}
}
}
response
{
"error": {
"root_cause": [],
"type": "search_phase_execution_exception",
"reason": "",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
"type": "aggregation_execution_exception",
"reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: [Object[]] at aggregation [10day]"
}
},
"status": 500
}
中央値の例
{
"took" : 10180,
"timed_out" : false,
"_shards" : {
"total" : 40,
"successful" : 40,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"category" : {
"doc_count_error_upper_bound" : 451394,
"sum_other_doc_count" : 197182706,
"buckets" : [
{
"key" : 20068,
"doc_count" : 950429,
"10day" : {
"buckets" : [
{
"key" : "2020-05-11 08:36:13-2020-05-21 08:36:13",
"from" : 1.589186173556E12,
"from_as_string" : "2020-05-11 08:36:13",
"to" : 1.590050173556E12,
"to_as_string" : "2020-05-21 08:36:13",
"doc_count" : 19633,
"median_price" : {
"values" : {
"50.0" : 800.0
}
}
}
]
},
"30day" : {
"buckets" : [
{
"key" : "2020-04-21 08:36:13-2020-05-21 08:36:13",
"from" : 1.587458173556E12,
"from_as_string" : "2020-04-21 08:36:13",
"to" : 1.590050173556E12,
"to_as_string" : "2020-05-21 08:36:13",
"doc_count" : 73913,
"median_price" : {
"values" : {
"50.0" : 800.0
}
}
}
]
}
}
]
}
}
}