gpt4 book ai didi

elasticsearch - 在Elastica中过滤全局聚合

转载 作者:行者123 更新时间:2023-12-02 22:58:28 24 4
gpt4 key购买 nike

我有使用ruflin / Elastica构建的 flex 查询,具有全局聚合。是否有可能以某种方式向其添加一些过滤器,与我的主查询分开。

看起来像这样:

    $query = new Query($boolQuery);

$categoryAggregation = new Terms('category_ids');
$categoryAggregation->setField('category_ids');
$categoryAggregation->setSize(0);

$manufacturerAggregation = new Terms('manufacturer_ids');
$manufacturerAggregation->setField('manufacturer_id');
$manufacturerAggregation->setSize(0);

$globalAggregation = new GlobalAggregation('global');
$globalAggregation->addAggregation($categoryAggregation);
$globalAggregation->addAggregation($manufacturerAggregation);

$query->addAggregation($globalAggregation);

我想向 manufacturer_idscategory_ids聚合添加一些自定义过滤器。目前,它们是从所有文档中汇总的。有什么方法可以通过Elastica API进行操作,以便对其应用一些过滤吗?

最佳答案

我是通过反复试验自己找到的,它如下:

$categoryAggregation = new Terms('category_ids');
$categoryAggregation->setField('category_ids');
$categoryAggregation->setSize(0);

$filter = new Filter('category_ids', $merchantIdQuery);
$filter->addAggregation($categoryAggregation);

$globalAggregation = new GlobalAggregation('global');
$globalAggregation->addAggregation($filter);

关于elasticsearch - 在Elastica中过滤全局聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43253497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com