2

I am trying to combine the filters for a FilterAggregation. Here the example:

$agg = new Elastica\Aggregation\Filters('size');

$filter1 = new Elastica\Query\Terms();       
$filter1->setTerms('color', $color);

$filter2 = new Elastica\Query\Terms();
$filter2->setTerms('material', $material);

$agg->addFilter($filter1);
$agg->addFilter($filter2);

The Problem here, ElasticSearch don't combine the filter and give me an array with 2 elements, where each filter is aggregated but not the aggregation from both filter with AND.

How to make the AND between the filter?

Thanks

Nik

Mutatos
  • 1,675
  • 4
  • 25
  • 55

1 Answers1

1

This is expected behaviour of Filters-Aggergation a per the documentation

Defines a multi bucket aggregations where each bucket is associated with a filter. Each bucket will collect all documents that match its associated filter.

If you wanted an AND of two filters you could use aggregation-filter along with bool-query

Example :

$agg = new Elastica\Aggregation\Filter('size');

$filter1 = new Elastica\Query\Terms();       
$filter1->setTerms('color', $color);  
$filter2 = new Elastica\Query\Terms();    
$filter2->setTerms('material',$material);

$boolQuery = new Elastica\Query\BoolQuery();
$boolQuery->addFilter($filter1);  
$boolQuery->addFilter($filter2);

$agg->setFilter($boolQuery);
keety
  • 17,231
  • 4
  • 51
  • 56