Java check packet with elasticsearch

Hey, programming the road is long, another pit a pit, climbed out also, when is the end!

Live for today, the program does not sleep!

Or expensive interfaces, or interfaces today, I was very food, stupid, but I still have to work! !

text:

Interface requirements is that, according to the number of vehicle models and the total number of online inquiries. Well, very simple, and I think simple, But, too dishes.

This investigation es, you must first get to the client

SearchRequestBuilder requestBuilder = transportClient.prepareSearch ( "Index Name") .setTypes ( "type name"); 
// here is to use a polymerization query directly attached to the code, and I still do not understand some of the first record to say
TermsAggregationBuilder termsBuilder = AggregationBuilders.terms("vehicleTypeCount").field("vehicleType");
requestBuilder.addAggregation(termsBuilder);
SearchResponse response = requestBuilder.execute().actionGet();
// get the set of packets 
Terms terms = response.getAggregations () get ( "vehicleTypeCount").;
Null ID = String; 
Long COUNT = 0L;
List <Object> = new new List the ArrayList <> ();
the HashMap <String, Object> = new new Map the HashMap <> ();
for (int I = 0; I <terms.getBuckets () .size (); i ++) {
// we check the above mentioned id here is the column name
the above mentioned id = terms.getBuckets () GET (i) .getKey () toString ();..
// COUNT is the total amount of natural friends
= terms.getBuckets COUNT () GET (i) .getDocCount ();.
// actual development, sometimes write code to write Mongolia, the definition of this map directly map.put (id, count) get away, but in fact there will be only one data map, which is a group kv, then I will put it up a map when a List
// in fact, I do not want this, this feeling is not very right, but sometimes for a task, it is not explore the root, and bigwigs have read the posts if you can teach me about Kazakhstan. (Id and count every time starting in place of different values, but there is only one data, is it jvm only see the surface character id, count?)
Map.put (id, count);
list.add ( Map);
}

result thus output is:
"typeCount": { 
      "1231 of":. 1, 
      "B":. 1 
    } 
wherein 123, b is the model la, the latter is the total number of natural.

Guess you like

Origin www.cnblogs.com/shuaidong/p/11011848.html