如何在弹性搜索中实现以下逻辑
SELECT COUNT(*)
FROM type1
WHERE type1.field_name IN (
SELECT field_name
FROM type2
WHERE
date_filed_name BETWEEN 'date1' AND 'date2');
和
SELECT COUNT(DISTINCT field3)
FROM type1
WHERE type1.field_name IN (
SELECT field_name
FROM type2
WHERE
date_filed_name BETWEEN 'date1' AND 'date2');
我在ES中有两种类型,需要实现这种逻辑。我尝试通过使用bool过滤器使用两个ES查询从一种类型获取并在另一种类型中使用它。但是有可能使用“术语过滤器查找”这样的结合来组合这两个查询吗?
我的子查询结果结果超过1500个唯一ID
我正在使用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
)
)
“agg_field”是“andi”。我通过执行另一个查询并通过PHP循环来创建termsFilter。