2017-04-06 2 views
1

グローバルアグリゲーションを使用してruflin/Elasticaを使用して作成された弾力的なクエリがあります。どういうわけか、メインのクエリとは別のフィルタを追加することは可能ですか?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経由でそれを行う方法はありますか?それで、いくつかのフィルタリングを適用しますか?

答えて

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); 
関連する問題