将这个Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码:GET tmall_order_wide_2023-03-07/_search { "aggs": { "groupbyprovince": { "terms": { "field": "province_name", "size": 40 }, "aggs": { "totalorder": { "sum": { "field": "total_amount" } } } } }, "size": 0 }
时间: 2023-04-06 08:03:33 浏览: 76
以下是Java中调用Elasticsearch的查询代码:
SearchRequest searchRequest = new SearchRequest("tmall_order_wide_2023-03-07");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermsAggregationBuilder aggregation = AggregationBuilders.terms("groupbyprovince").field("province_name").size(40)
.subAggregation(AggregationBuilders.sum("totalorder").field("total_amount"));
searchSourceBuilder.aggregation(aggregation);
searchSourceBuilder.size(0);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
相关问题
将这个Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码:GET tmall_dau_info_2023-03-03/_search { "query": { "match": { "is_new": "1" } }, "aggs": { "groupbychannel": { "terms": { "field": "channel", "size": 15 } } }, "size": 0 }
以下是将该Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码:
SearchRequest searchRequest = new SearchRequest("tmall_dau_info_2023-03-03");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("is_new", "1");
searchSourceBuilder.query(matchQueryBuilder);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("groupbychannel").field("channel").size(15);
searchSourceBuilder.aggregation(aggregationBuilder);
searchSourceBuilder.size(0);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
其中,client是Elasticsearch客户端对象。
请用docker-compose写出下面这串代码: docker run --name es-s2 --restart=always -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -v /mydata/se_cluster/es-s2/config:/usr/share/elasticsearch/config -v /mydata/se_cluster/es-s2/data:/usr/share/elasticsearch/data -v /mydata/se_cluster/es-s2/plugins:/usr/share/elasticsearch/plugins -v /mydata/se_cluster/es-s2/logs:/usr/share/elasticsearch/logs -e TAKE_FILE_OWNERSHIP="true" -d elasticsearch:7.9.0
version: '3'
services:
es-s2:
container_name: es-s2
restart: always
ports:
- "9200:9200"
- "9300:9300"
environment:
- discovery.type=single-node
- TAKE_FILE_OWNERSHIP=true
volumes:
- /mydata/se_cluster/es-s2/config:/usr/share/elasticsearch/config
- /mydata/se_cluster/es-s2/data:/usr/share/elasticsearch/data
- /mydata/se_cluster/es-s2/plugins:/usr/share/elasticsearch/plugins
- /mydata/se_cluster/es-s2/logs:/usr/share/elasticsearch/logs
image: elasticsearch:7.9.0
detach: true
阅读全文