我使用bool过滤器进行基数和值计数聚合。我的术语过滤器有近2000个术语,因此需要花费大量时间来加载。另外对我来说,无法通过指定过滤条件手动测试它。
我刚看过“条款查询”和“#39;特征。我是否有可能在术语查找中指定数组或其他查询,因此我避免首先使用PHP获取术语,然后在聚合查询中使用它们。
我上面提到的操作的PHP代码是这样的:
$reportParams['body']['query'] = array(
"filtered" => array(
"filter" => array(
"bool" => array(
"must" => array(
"range" => array(
"time" => array(
"gt" => $start,
"lt" => $end
)
)
),
"should" =>$termFilter
)
)
)
);
$reportParams['body']['aggs'] = array(
"distinct_user_count" => array(
"cardinality" => array(
"field" => $details->agg_field
)
),
"daily_event_count" => array(
"value_count" => array(
"field" => $details->agg_field
)
)
);
和termsFilter是这样的数组:
[0] => Array
(
[term] => Array
(
[andi] => 84cc04c6059fb490
)
)
[1] => Array
(
[term] => Array
(
[andi] => af9cbd253100f2c7
)
)
[2] => Array
(
[term] => Array
(
[andi] => c1a3fcf0fefe7107
)
)
[3] => Array
(
[term] => Array
(
[andi] => b3a630084347fb2f
)
)