Retrieve aggregation results after processing filters not working

So I've got a query. It makes a few filters and then add an aggregations.


$agg = new Elastica\Aggregation\Terms('agg_name');


$resultSet = $search->search();
$aggregations = $resultSet->getAggregations();


So the problem now is, whenI var_dump my $aggregations variable I find out that my query filters were not processed.
In other words the Terms aggregation correctly groups results by Name, but it does not group the QUERY results by name, rather they group ALL the names in my Elasticsearch index.

So rather than having a result as follow (the idea) :

Name : X, doc_count : 3
Name : Y, doc_count : 3

Well, I get all the names grouped :

Name : X, doc_count : 62
Name : Y, doc_count : 97
Name : Z, doc_count : 18
Name : A, doc_count : 36
Name : B, doc_count : 47
Name : C, doc_count : 81

Any idea why aren't my aggregations taking my filters into consideration?

I'm not super familiar with Elastica's functionality, is it possible to dump the final search result in JSON format? I'd like to see what the final request looks like. It may be a syntax issue.

Another possibility is the presence of multi-valued fields. If Name has multiple values, the filter can match one of the values but the terms agg will collect all values.

Thank you for your answer, I'd found the issue. It was because Elastica was putting the filters in a post_filter, and not in the query, while the Aggregations were looking for filters in the query, so they were never executing the filters. I had to manage to put them inside the query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.