To group queries by aggregation:
SearchResponse response = Client.preparesearch (Index_douban). Settypes (Type_douban)
. Addaggregation (
Aggregationbuilders.terms ("By_" +tag). Field (TAG). Size (1000)
)
. Execute (). Actionget ();
Terms Terms = Response.getaggregations (). Get ("By_" +tag);
For (Bucket b:terms.getbuckets ()) {
Sum sum = b.getaggregations (). Get ("sum");
List.add (String) B.getkey ());
System.out.println ("Filedname:" +b.getkey () + "Doccount:" +b.getdoccount ());
}
It is important to note that the return quantity is not the same as before SetSize (), but to set the size of the Aggregationbuilders line, and second: for non-numeric and English fields, such a combination of queries by default will be word processing, So to use mapping to set the field of the word or not, this part of the detailed description later.
Distributed search engine Elasticsearch (insert data and Java API II)