Migrating from facets to aggregations

Hi I am migrating an application that current uses elasticsearch and while most of the migration was straightforward and we were able to migrate most of the code, there are a few gray areas that we're not being able to migrate properly, as an example take the facet features that have been deprecated in favor of aggregations we've been stuck for a couple of hours trying to migrate the following fragment without success:

protected static void addFacets(InstrumentSearchInstruction instruction, SearchRequestBuilder search, List<String> facetFields) {
Map<String, Set<String>> filtersPerField = getFacetFiltersPerField(instruction);

for (String facetField : facetFields) {
  BoolQueryBuilder facetFilter = buildFilterForFacet(filtersPerField, facetField);   search.addFacet(termsFacet(facetField).field(facetField).size(Integer.MAX_VALUE).allTerms(shouldReturnAllTermsForFacet(facetField)).facetFilter(facetFilter));
 }
}

Any ideas about how to migrate this fragment from facets to aggregations?

We understand that first steps would be to change the addFacet to use aggregation and termsFacet to terms but the allTerms and faceFilter that are then applied we are struggling with it.

1 Like

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