将这个Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码:GET tmall_dau_info_2023-03-03/_search { "aggs": { "groupbyisnew": { "terms": { "field": "is_new", "size": 2 } } }, "size": 0 }
时间: 2023-04-06 09:03:01 浏览: 102
Java操作Elasticsearch
以下是Java中调用Elasticsearch的查询代码:
SearchRequest searchRequest = new SearchRequest("tmall_dau_info_2023-03-03");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("groupbyisnew").field("is_new").size(2);
searchSourceBuilder.aggregation(aggregationBuilder);
searchSourceBuilder.size(0);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
其中,client是Elasticsearch的Java客户端。
阅读全文