The following fields are substring polymerization, taken 'your_field' before eight polymerized
Script script = new Script("doc['your_field'].getValue().substring(0,8)"); CardinalityAggregationBuilder pointCardinality = AggregationBuilders.cardinality("pointCardinality").script(script).precisionThreshold(400000); SearchResponse totalPointResponse = client.prepareSearch("index_name").setTypes("type_name") .setQuery(boolQueryBuilder) .addAggregation(pointCardinality) .execute() .actionGet(); Cardinality cardinalityTotal = totalPointResponse.getAggregations().get("pointCardinality");
Multi polymerization field, is the need to modify the content Script (plainless), for example, selected according to the field conditions and the like:
eg:
if(doc['camera_dev_name'].size() != 0){doc['camera_dev_name'].getValue().substring(0,8)}else{doc['ap_dev_name.keyword'].getValue().substring(0,8)}
Script simply by changing the content.