POST /nba/_search
{
"query": {
"term": {
"teamNameEn.keyword": {
"value": "Rockets"
}
}
},
"aggs": {
"counAget": {
"cardinality": {
"field": "playYear"
}
}
},
"size": 0
}
@Test
public void test05() throws IOException {
SearchRequest searchRequest = new SearchRequest("nba");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.termQuery("teamName.keyword","火箭")).size(100);
CardinalityAggregationBuilder cardinalityAggregationBuilder = AggregationBuilders.cardinality("playYear").field("playYear");
searchSourceBuilder.aggregation(cardinalityAggregationBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT);
Cardinality valueCount = search.getAggregations().get("playYear");
long value = valueCount.getValue();
System.out.println(value);
}