Facet to Aggregations (library 1.7 to 6.3)

Hi, I'm porting my project's library version from 1.7.5 to 6.3.0.

Here is the previous code:

	SearchRequestBuilder srBuilder = client.prepareSearch(indexArr);

	srBuilder.setQuery(matchAllQuery());    	
	srBuilder.addFacet(facetBuilder);
	    	
	SearchResponse response = srBuilder.execute().actionGet();
	
	Facets facets = response.getFacets();
	TermsStatsFacet facet = facets.facet("termsStat");

	List<? extends TermsStatsFacet.Entry> entries = facet.getEntries();
	
	LinkedHashMap<String, Double> resultMap = new LinkedHashMap<String, Double>();
	for(Entry stat : entries) {
		resultMap.put(stat.getTerm().toString(), stat.getTotal());
	}

Because 'Facets' are deprecated, I have to use 'Aggregations'.

below is the code that I'm working on:

	SearchRequestBuilder srBuilder = client.prepareSearch(indexArr);

	srBuilder.setQuery(matchAllQuery());
	srBuilder.addAggregation(aggregationBuilder);    	

 	SearchResponse response = srBuilder.execute().actionGet();

	Aggregations aggregations = response.getAggregations();
	TermsAggregator tAggregator = aggregations.get("termsStat");

	List<? extends TermsStatsFacet.Entry> entries = facet.getEntries();

	LinkedHashMap<String, Double> resultMap = new LinkedHashMap<String, Double>();
	for(Entry stat : entries) {
		resultMap.put(stat.getTerm().toString(), stat.getTotal());
	}

I'm having trouble porting from the 'TermsStatsFacet.Entry' part.

It's hard to find the API document related 'TermsStatsFacet'. What should I do?

Any comment would be appreciated. Thanks.

Read this may be?

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_bucket_aggregations.html#java-aggs-bucket-terms

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