# Facet to Aggregations (library 1.7 to 6.3)

**URL:** <https://discuss.elastic.co/t/facet-to-aggregations-library-1-7-to-6-3/156284>\
**Category:** Elasticsearch\
**Created:** [November 12, 2018, 12:07pm UTC](https://discuss.elastic.co/t/facet-to-aggregations-library-1-7-to-6-3/156284 "2018-11-12T12:07:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![byeong\_seok\_park](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byeong_seok_park/32/48056_2.png) [@byeong\_seok\_park](https://discuss.elastic.co/u/byeong_seok_park)\
**Post date:** [November 12, 2018, 12:07pm UTC](https://discuss.elastic.co/t/facet-to-aggregations-library-1-7-to-6-3/156284/1 "2018-11-12T12:07:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 12, 2018, 12:27pm UTC](https://discuss.elastic.co/t/facet-to-aggregations-library-1-7-to-6-3/156284/2 "2018-11-12T12:27:29Z")

</div>

Read this may be?

[https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/\_bucket\_aggregations.html#java-aggs-bucket-terms](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/_bucket_aggregations.html#java-aggs-bucket-terms)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 10, 2018, 12:27pm UTC](https://discuss.elastic.co/t/facet-to-aggregations-library-1-7-to-6-3/156284/3 "2018-12-10T12:27:33Z")

</div>

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