将这个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 }
时间: 2023-04-08 22:00:29 浏览: 74
以下是将该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客户端对象。
相关问题
将这个Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码:GET tmall_order_wide_2023-03-07/_search { "aggs": { "groupbyskuid": { "terms": { "field": "sku_id", "size": 50 }, "aggs": { "totalskuamount": { "sum": { "field": "total_amount" } } } } }, "size": 0 }
以下是将该Elasticsearch查询写成JAVA中调用Elasticsearch的查询代码的示例:
SearchRequest searchRequest = new SearchRequest("tmall_order_wide_2023-03-07");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("groupbyskuid").field("sku_id").size(50);
SumAggregationBuilder sumAggregationBuilder = AggregationBuilders.sum("totalskuamount").field("total_amount");
aggregationBuilder.subAggregation(sumAggregationBuilder);
searchSourceBuilder.aggregation(aggregationBuilder);
searchSourceBuilder.size(0);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
请用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
阅读全文