【问题标题】:Filtering global aggregation in Elastica在 Elastica 中过滤全局聚合
【发布时间】:2017-04-06 11:12:40
【问题描述】:

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

看起来像这样:

    $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 来实现,以便对其应用一些过滤?

【问题讨论】:

    标签: elasticsearch elastica


    【解决方案1】:

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

    $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);
    

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多