简体   繁体   中英

How to get facet value for all fields using Java API

I'm new to Elasticsearch and tried to query some sample documents. I issued the following query using the Java API . This query fetched me the correct result. It returned the names of all categories. Now I want the count of all names of a category. Could you explain me how to do that? I'm sorry for my bad English.

SearchResponse sr = client.prepareSearch()
         .addField("Category")
         .setQuery(QueryBuilders.matchAllQuery())
         .addFacet(FacetBuilders.termsFacet("f")
         .field("Category"))
         .execute()
         .actionGet();

Look at the Count API to count your results if you not want to get the result set (matched documents) but only the count.

If you want to get the result set, you get the result size in the response for every filter or query request too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM