【发布时间】:2018-07-30 14:00:57
【问题描述】:
$params2 = [
'index' => 'index',
'type' => "items",
'body' => [
'aggs' => [
"types" => [
"filter" => [
"bool" => [
"should" => [
["term" => ["type_id" => 1]],
["term" => ["type_id" => 2]]
]
]
],
"aggs" => [
"types" =>[
["terms" => ["field" => "type_id","size" => 4]],
"aggs" =>[
"top" => [
["top_hits" => ["size" => 2]]
]
]
]
]
]
],
]
];
当我将此参数传递给 $elastic->search($params2);
它返回我这个异常
{"error":{"root_cause":[{"type":"unknown_named_object_exception","reason":"Unknown BaseAggregationBuilder [0]","line":1,"col":117}]," type":"unknown_named_object_exception","reason":"Unknown BaseAggregationBuilder [0]","line":1,"col":117},"status":400}
我正在使用 ErickTamayo/laravel-scout-elastic 包
【问题讨论】:
-
去掉
["terms" => ["field" => "type_id","size" => 4]],周围的方括号 =>"terms" => ["field" => "type_id","size" => 4], -
谢谢,现在我有了新异常 {"error":{"root_cause":[{"type":"parsing_exception","reason":"[top 的聚合定义以 [START_ARRAY ],预期为 [START_OBJECT]。","line":1,"col":164}],"type":"parsing_exception","reason":"[top 的聚合定义以 [START_ARRAY] 开头,预期为一个 [START_OBJECT].","line":1,"col":164},"status":400}
标签: php laravel elasticsearch