ElasticSearch的常用增删改查DSL和代码

es增删改查常用语法

我们日常开发中,操作数据库写sql倒是不可能忘记,但是操作es的dsl语句有时候很容易忘记,特地记录一下方便查找。

DSL语句

1、创建索引

-- 创建索引
PUT /my_index
{"mappings": {"properties": {"title": {"type": "text"},"description": {"type": "text"},"timestamp": {"type": "date"}}}
}

2、插入文档

-- 插入文档
POST /my_index/_doc/1
{"title": "Sample Document","description": "This is a sample document for Elasticsearch","timestamp": "2022-01-01"
}

3、更新文档

-- 更新文档
POST /my_index/_update/主键值
{"doc": {"description": "Updated description"}
}

4、删除文档(单独、多个、全部)

-- 删除单条文档
DELETE /my_index/_doc/或者
-- 删除单条文档  
POST 索引名/_delete_by_query
{"query":{"term":{"_id":4043}}
}-- 删除索引中的所有数据
POST my_index/_delete_by_query
{"query": { "match_all": {}}
}

5、删除索引

-- 删除索引
DELETE /my_index

6、设置索引别名

-- 设置索引别名
POST /_aliases{"actions": [{"add": {"index": "my_index2", "alias": "my_index"}}]}

7、设置切片和副本数量

-- 设置切片和副本数量
PUT your_index
{"mappings" : {"properties" : {#索引字段(略)}}"settings" : {"number_of_shards" : 3,"number_of_replicas" : 1}
}

8、查询

-- 查询单个条件
POST /my_index/_search
{"query": {"bool": {"must": {"term": {"messageId": "CS202303160008-2"}}}}
}-- 分页排序查询  	不带其他条件POST /my_index/_search
{"query": {"match_all": {}},"from": 0,"size": 20,"sort": [{"createdAt": {"order": "desc"}}]
}
-- 分页排序查询  	带其他条件
{"query": {"bool": {"must": [{"prefix": {"action": "aa开头"}},{"wildcard": {"param": "*左右匹配内容*"}}],"must_not": [],"should": []}},"from": 0,"size": 10,"sort": [{"createdAt": {"order": "desc"}}]
}

9、统计

POST /my_index/_count
{"query": {"bool": {"must": {"term": {"messageId": "CS202303160008-2"}}}}
}

代码

pom依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo.sdk</groupId>
<artifactId>elasticsearch-util</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>elasticsearch-util</name>
<description>Spring Boot Support for elasticsearch-util</description><properties><java.version>11</java.version><elasticsearch.version>7.10.0</elasticsearch.version><spring-boot.version>2.7.0</spring-boot.version><hutool.version>5.8.15</hutool.version><pagehelper.version>1.4.2</pagehelper.version>
</properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId><version>${spring-boot.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><version>${spring-boot.version}</version><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId><version>${spring-boot.version}</version></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>${elasticsearch.version}</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>${pagehelper.version}</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool.version}</version></dependency>
</dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>11</source><target>11</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin></plugins>
</build>

1、ES配置类

	import cn.hutool.core.text.CharSequenceUtil;import org.apache.http.auth.AuthScope;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.client.CredentialsProvider;import org.apache.http.impl.client.BasicCredentialsProvider;import org.springframework.boot.context.properties.ConfigurationProperties;/*** ES配置类* @author ppp* @date 2023/3/21*/@ConfigurationProperties(prefix = "elasticsearch.config")public class ElasticsearchProperties {/*** 域名*/private String host;/*** 端口*/private String port;/*** 用户名*/private String username;/*** 密码*/private String password;/*** 连接超时时间*/private int connectTimeOut;/*** 连接超时时间*/private int socketTimeOut;/*** 获取连接的超时时间*/private int connectionRequestTimeOut;/*** 获取搜索的超时时间*/private long searchRequestTimeOut = 10000L;/*** 最大连接数*/private int maxConnectNum;/*** 最大路由连接数*/private int maxConnectPerRoute;public String getHost() {return host;}public void setHost(String host) {this.host = host;}public String getPort() {return port;}public void setPort(String port) {this.port = port;}public int getConnectTimeOut() {return connectTimeOut;}public void setConnectTimeOut(int connectTimeOut) {this.connectTimeOut = connectTimeOut;}public int getSocketTimeOut() {return socketTimeOut;}public void setSocketTimeOut(int socketTimeOut) {this.socketTimeOut = socketTimeOut;}public int getConnectionRequestTimeOut() {return connectionRequestTimeOut;}public void setConnectionRequestTimeOut(int connectionRequestTimeOut) {this.connectionRequestTimeOut = connectionRequestTimeOut;}public long getSearchRequestTimeOut() {return searchRequestTimeOut;}public void setSearchRequestTimeOut(long searchRequestTimeOut) {this.searchRequestTimeOut = searchRequestTimeOut;}public int getMaxConnectNum() {return maxConnectNum;}public void setMaxConnectNum(int maxConnectNum) {this.maxConnectNum = maxConnectNum;}public int getMaxConnectPerRoute() {return maxConnectPerRoute;}public void setMaxConnectPerRoute(int maxConnectPerRoute) {this.maxConnectPerRoute = maxConnectPerRoute;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public CredentialsProvider getCredentialsProvider() {if (CharSequenceUtil.isNotBlank(username) && CharSequenceUtil.isNotBlank(password)) {CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));return credentialsProvider;}return null;}}

2、ES工具自动配置类

import cn.hutool.core.text.CharSequenceUtil;
import com.demo.sdk.elasticsearch.template.ElasticsearchUtilTemplate;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/**
* ES工具自动配置类
* @author ppp
* @date 2023/3/21
*/
@Configuration
@ConditionalOnClass(ElasticsearchUtilTemplate.class)
@EnableConfigurationProperties(ElasticsearchProperties.class)
public class ElasticsearchUtilAutoConfiguration {@Bean@ConditionalOnMissingBeanpublic RestHighLevelClient esRestClient(ElasticsearchProperties esearchProperties) {if (esearchProperties == null) {throw new NullPointerException("Es Configuration Properties Is Null");}String host = esearchProperties.getHost();String port = esearchProperties.getPort();RestClientBuilder builder;if (CharSequenceUtil.isNotBlank(host) && CharSequenceUtil.isBlank(port)) {builder = RestClient.builder(HttpHost.create(host));}else {builder = RestClient.builder(new HttpHost(host, Integer.parseInt(port)));}// 异步httpclient连接延时配置builder.setRequestConfigCallback(requestConfigBuilder -> {requestConfigBuilder.setConnectTimeout(esearchProperties.getConnectTimeOut());requestConfigBuilder.setSocketTimeout(esearchProperties.getSocketTimeOut());requestConfigBuilder.setConnectionRequestTimeout(esearchProperties.getConnectionRequestTimeOut());return requestConfigBuilder;});// 异步httpclient连接数配置builder.setHttpClientConfigCallback(httpClientBuilder -> {httpClientBuilder.setMaxConnTotal(esearchProperties.getMaxConnectNum());httpClientBuilder.setMaxConnPerRoute(esearchProperties.getMaxConnectPerRoute());httpClientBuilder.setDefaultCredentialsProvider(esearchProperties.getCredentialsProvider());return httpClientBuilder;});return  new RestHighLevelClient(builder);}@Bean@ConditionalOnMissingBeanpublic ElasticsearchUtilTemplate elasticsearchUtilTemplate(RestHighLevelClient esRestClient, ElasticsearchProperties elasticsearchProperties) {if (esRestClient == null) {throw new NullPointerException("RestHighLevelClient init Error");}return new ElasticsearchUtilTemplate(esRestClient,elasticsearchProperties.getSearchRequestTimeOut());}}

3、自动装配配置

装配要生效需要ElasticsearchUtilAutoConfiguration加入springboot的自动装配文件spring.factories
这是spring配置的特定目录文件,自己新建一个,名字和目录要一致
在这里插入图片描述

# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.demo.sdk.elasticsearch.config.ElasticsearchUtilAutoConfiguration

4、定义一个模板工具类

	import cn.hutool.json.JSONUtil;import com.github.pagehelper.Page;import com.github.pagehelper.page.PageMethod;import com.demo.sdk.elasticsearch.exception.ElasticsearchErrorException;import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;import org.elasticsearch.action.bulk.BulkRequest;import org.elasticsearch.action.bulk.BulkResponse;import org.elasticsearch.action.delete.DeleteRequest;import org.elasticsearch.action.delete.DeleteResponse;import org.elasticsearch.action.get.GetRequest;import org.elasticsearch.action.get.GetResponse;import org.elasticsearch.action.index.IndexRequest;import org.elasticsearch.action.index.IndexResponse;import org.elasticsearch.action.search.SearchRequest;import org.elasticsearch.action.search.SearchResponse;import org.elasticsearch.action.support.master.AcknowledgedResponse;import org.elasticsearch.action.update.UpdateRequest;import org.elasticsearch.action.update.UpdateResponse;import org.elasticsearch.client.RequestOptions;import org.elasticsearch.client.RestHighLevelClient;import org.elasticsearch.client.core.CountRequest;import org.elasticsearch.client.core.CountResponse;import org.elasticsearch.client.indices.CreateIndexRequest;import org.elasticsearch.client.indices.CreateIndexResponse;import org.elasticsearch.common.unit.TimeValue;import org.elasticsearch.common.xcontent.XContentType;import org.elasticsearch.search.SearchHit;import org.elasticsearch.search.builder.SearchSourceBuilder;import java.util.ArrayList;import java.util.List;import java.util.Map;/*** ES搜索引擎模板* @author ppp* @date 2023/3/21*/public class ElasticsearchUtilTemplate {private final RestHighLevelClient esRestClient;private final long searchRequestTimeOut;public ElasticsearchUtilTemplate(RestHighLevelClient esRestClient, long searchRequestTimeOut) {this.searchRequestTimeOut = searchRequestTimeOut;this.esRestClient = esRestClient;}/*** 列表查询** @param searchSourceBuilder SearchSourceBuilder* @param clazz               返回结果class对象* @param indices             ES索引* @return java.util.List    对象列表*/public <T> List<T> listSearch(SearchSourceBuilder searchSourceBuilder, Class<T> clazz, String... indices) {Page<T> resultPage = PageMethod.getLocalPage();boolean isResultPage = resultPage != null;if (isResultPage) {PageMethod.clearPage();searchSourceBuilder.from((int) resultPage.getStartRow());searchSourceBuilder.size(resultPage.getPageSize());}if (isResultPage && resultPage.isCount()) {resultPage.setTotal(count(searchSourceBuilder, indices));}SearchResponse searchResponse = search(searchSourceBuilder, indices);List<T> resultList = formatSearchResult(searchResponse, clazz);if (isResultPage && resultPage.isCount()) {resultPage.addAll(resultList);return resultPage;}return resultList;}public SearchResponse search(SearchSourceBuilder searchSourceBuilder, String... indices) {SearchRequest searchRequest = new SearchRequest(indices);searchSourceBuilder.timeout(TimeValue.timeValueMillis(searchRequestTimeOut));searchRequest.source(searchSourceBuilder);return search(searchRequest);}public SearchResponse search(SearchRequest searchRequest) {try {return esRestClient.search(searchRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 统计数量** @param searchSourceBuilder SearchSourceBuilder* @param indices             ES索引* @return CountResponse*/public long count(SearchSourceBuilder searchSourceBuilder, String... indices) {CountRequest countRequest = new CountRequest(indices);searchSourceBuilder.timeout(TimeValue.timeValueMillis(searchRequestTimeOut));countRequest.query(searchSourceBuilder.query());return count(countRequest, RequestOptions.DEFAULT).getCount();}public CountResponse count(CountRequest countRequest, RequestOptions options) {try {return esRestClient.count(countRequest, options);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 创建索引** @param createIndexRequest CreateIndexRequest* @return CreateIndexResponse*/public CreateIndexResponse createIndices(CreateIndexRequest createIndexRequest) {try {return esRestClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 删除索引(谨慎操作,索引下所有数据都将清空)** @param index 索引名称* @return AcknowledgedResponse*/public AcknowledgedResponse deleteIndex(String index) {DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest();deleteIndexRequest.indices(index);return deleteIndices(deleteIndexRequest);}/*** 删除索引(谨慎操作,索引下所有数据都将清空)** @param deleteIndexRequest DeleteIndexRequest* @return AcknowledgedResponse*/public AcknowledgedResponse deleteIndices(DeleteIndexRequest deleteIndexRequest) {try {return esRestClient.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 插入数据** @param index  索引* @param id     唯一id* @param source 插入对象* @return IndexResponse*/public IndexResponse add(String index, Object id, Object source) {IndexRequest indexRequest = new IndexRequest(index).id(String.valueOf(id));indexRequest.source(JSONUtil.toJsonStr(source), XContentType.JSON);try {return esRestClient.index(indexRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 批量插入数据* 建议:数量控制在5000以内** @param index     索引* @param sourceMap 数据<唯一id,对象>* @return BulkResponse*/public BulkResponse addBulk(String index, Map<String, Object> sourceMap) {BulkRequest request = new BulkRequest();sourceMap.forEach((id, source) -> {request.add(new IndexRequest(index).id(id).source(JSONUtil.toJsonStr(source), XContentType.JSON));});try {return esRestClient.bulk(request, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 获取数据** @param getRequest GetRequest* @return GetResponse*/public GetResponse get(GetRequest getRequest) {try {return esRestClient.get(getRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 更新数据** @param updateRequest UpdateRequest* @return UpdateResponse*/public UpdateResponse update(UpdateRequest updateRequest) {try {return esRestClient.update(updateRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 删除数据** @param deleteRequest DeleteRequest* @return DeleteResponse*/public DeleteResponse delete(DeleteRequest deleteRequest) {try {return esRestClient.delete(deleteRequest, RequestOptions.DEFAULT);} catch (Exception e) {throw new ElasticsearchErrorException(e.getMessage(), e.getCause());}}/*** 格式化搜索结果** @param searchResponse 搜索结果* @param clazz          返回对象* @return java.util.List*/public <T> List<T> formatSearchResult(SearchResponse searchResponse, Class<T> clazz) {SearchHit[] searchHits = searchResponse.getHits().getHits();List<T> resultList = new ArrayList<T>();for (SearchHit searchHit : searchHits) {resultList.add(JSONUtil.toBean(searchHit.getSourceAsString(), clazz));}return resultList;}}

5、定义一个异常

/**
* 错误异常
* @author ppp
* @date 2023/3/21
*/
public class ElasticsearchErrorException extends RuntimeException {public ElasticsearchErrorException(String message) {super(message);}public ElasticsearchErrorException(String message, Throwable cause) {super(message, cause);}
}

6、application.yml配置

# elasticsearch
elasticsearch.config:host: 127.0.0.1port: 9200username: adminpassword: admin123connect-time-out: 1000socket-time-out: 30000connection-request-time-out: 500search-request-time-out: 5000max-connect-num: 100max-connect-per-route: 100

7、测试

class DemoApplicationTests {/*** 获取ElasticsearchUtilTemplate模板*/@Autowiredprivate ElasticsearchUtilTemplate elasticsearchTemplate;/*** 分页查询*/
@Test
void getListPage() {// 分页PageHelper.startPage(1, 10);SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();// 筛选boolQueryBuilder.filter(QueryBuilders.termQuery("ip", "192.168.0.1"));// 筛选多个值  类似mysq  termsQuery和termQuery区别boolQueryBuilder.filter(QueryBuilders.termsQuery("name", Arrays.asList("张三","李四"));// 模糊boolQueryBuilder.must(QueryBuilders.wildcardQuery("ext1", "*测试*"));searchSourceBuilder.query(boolQueryBuilder);// 排序searchSourceBuilder.sort("createTime", SortOrder.DESC);List<StudyLogIndex> logIndexList = this.elasticsearchTemplate.listSearch(searchSourceBuilder, StudyLogIndex.class, index);PageInfo<StudyLogIndex> studyLogIndexPageInfo = new PageInfo<>(logIndexList);System.out.println(JSONUtil.toJsonStr(studyLogIndexPageInfo));
}/*** 统计*/
@Test
void countTest() {// 分页PageHelper.startPage(1, 10);SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();// 筛选boolQueryBuilder.filter(QueryBuilders.termQuery("ip", "127.0.0.1"));// 模糊boolQueryBuilder.must(QueryBuilders.wildcardQuery("ext2", "*用*"));searchSourceBuilder.query(boolQueryBuilder);CountResponse count = elasticsearchTemplate.count(searchSourceBuilder, index);System.out.println("统计总数:"+ count.getCount());
}/*** 删除索引*/
@Test
void deleteIndicesTest() {elasticsearchTemplate.deleteIndex(index);
}/*** 创建es索引*/
@Test
void createIndicesTest() {CreateIndexRequest createIndexRequest = new CreateIndexRequest(index);createIndexRequest.mapping("{\n" +"    \"properties\": {\n" +"        \"globalId\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"site\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"tag\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"uid\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"classId\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"courseId\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"videoId\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"startTime\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"time\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"ip\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"start\": {\n" +"            \"type\": \"integer\"\n" +"        },\n" +"        \"end\": {\n" +"            \"type\": \"integer\"\n" +"        },\n" +"        \"createTime\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"ext1\": {\n" +"            \"type\": \"keyword\"\n" +"        },\n" +"        \"ext2\": {\n" +"            \"type\": \"keyword\"\n" +"        }\n" +"    }\n" +"}", XContentType.JSON);elasticsearchTemplate.createIndices(createIndexRequest);
}/*** 插入es数据*/
@Test
void addDataTest() {for (int i = 0; i < 10; i++) {StudyLogIndex studyLogIndex = new StudyLogIndex();studyLogIndex.setGlobalId("CX"+i);studyLogIndex.setSite("CX");studyLogIndex.setTag("SUCCESS");studyLogIndex.setUid(12000000L+i);studyLogIndex.setClassId(123456L);studyLogIndex.setCourseId(123456L);studyLogIndex.setVideoId(123456L);studyLogIndex.setStartTime(123456L);studyLogIndex.setTime(123456L);studyLogIndex.setIp("127.0.0.1");studyLogIndex.setStart(0);studyLogIndex.setEnd(0);studyLogIndex.setCreateTime(0L);studyLogIndex.setExt1("测试es工具");studyLogIndex.setExt2("备用");elasticsearchTemplate.add(index, studyLogIndex.getGlobalId(), studyLogIndex);}
}/*** 批量插入es*/
@Test
void bulkAddDataTest() {Map<String, Object> map = new HashMap<>(16);for (int i = 100; i < 1000; i++) {StudyLogIndex studyLogIndex = new StudyLogIndex();studyLogIndex.setGlobalId(IdUtil.getSnowflakeNextIdStr());studyLogIndex.setSite("ZJ");studyLogIndex.setTag("SUCCESS");studyLogIndex.setUid(12000000L+i);studyLogIndex.setClassId(123456L);studyLogIndex.setCourseId(123456L);studyLogIndex.setVideoId(123456L);studyLogIndex.setStartTime(123456L);studyLogIndex.setTime(123456L);studyLogIndex.setIp("192.168.0.3");studyLogIndex.setStart(0);studyLogIndex.setEnd(0);studyLogIndex.setCreateTime(0L);studyLogIndex.setExt1("批量测试es工具");studyLogIndex.setExt2("备用");map.put(studyLogIndex.getGlobalId(), studyLogIndex);}elasticsearchTemplate.addBulk(index, map);
}/*** 聚合检索*/
@Test
void aggregateTest() {SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();// 聚合检索不设置大小会默认只返回10个统计结果TermsAggregationBuilder field = AggregationBuilders.terms("group_by_ip").field("ip").size(1000);searchSourceBuilder.aggregation(field).size(10);SearchResponse search = elasticsearchTemplate.search(searchSourceBuilder, index);System.out.println(JSONUtil.toJsonStr(search));Map<String, Long> countMap = AggregationsUtil.getCountMap(search.getAggregations());System.out.println(JSONUtil.toJsonStr(countMap));
}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/631417.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

GEE中Landsat、Sentinel、Modis主要数据集区别

一、Landsat 1. Collection 1/2 的区别 Collection 2 是Landsat Level 1 数据的又一次重大再处理&#xff0c;显著提高了绝对地理定位精度。 Collection1Collection2时间跨度1972~2021底1972~至今数据等级level 1level1&#xff1a;1972~2021底 level2&#xff1a;1982~至今 …

路由器初始化配置、功能配置

实验环境 拓扑图 Ip规划表&#xff08;各组使用自己的IP规划表&#xff09; 部门 主机数量 网络地址 子网掩码 网关 可用ip Vlan 市场部 38 192.168.131.0 255.255.255.0 192.168.131.1 2-254 11 研发部 53 192.168.132.0 255.255.255.0 192.168.132.1 2-2…

Oracle21C + PLSQL Developer 15 + Oracle客户端21安装配置完整图文版

一、Oracle21C PLSQL Developer 15 Oracle客户端文件下载 1、Oracl21C下载地址&#xff1a;Database Software Downloads | Oracle 中国 2、 PLSQL Developer 15下载地址&#xff1a;Registered download PL/SQL Developer - Allround Automations 3、 Oracle 客户端下载地址…

全球光伏知名企业-晶科能源联合泛微采知连,建立文控管理平台

晶科能源股份有限公司&#xff08;简称“晶科能源”&#xff09;是一家全球知名、极具创新力的太阳能科技企业。 &#xff08;图片素材来自晶科能源官网&#xff09; 公司战略性布局光伏产业链核心环节&#xff0c;聚焦光伏产品一体化研发制造和清洁能源整体解决方案提供&…

[晓理紫]每日论文分享(有中文摘要,源码或项目地址)--具身智能、强化学习

专属领域论文订阅 VX关注 晓理紫&#xff0c;每日更新论文&#xff0c;如感兴趣&#xff0c;请转发给有需要的同学&#xff0c;谢谢支持 分类: 大语言模型LLM视觉模型VLM扩散模型视觉导航具身智能&#xff0c;机器人强化学习开放词汇&#xff0c;检测分割 [晓理紫]每日论文分享…

【LabVIEW FPGA入门】FPGA中的数学运算

数值控件选板上的大部分数学函数都支持整数或定点数据类型&#xff0c;但是需要请注意&#xff0c;避免使用乘法、除法、倒数、平方根等函数&#xff0c;此类函数比较占用FPGA资源&#xff0c;且如果使用的是定点数据或单精度浮点数据仅适用于FPGA终端。 1.整数运算 支持的数…

【Java】IDEA中的JFormDesigner使用教程

目录 1 安装 JFormDesigner 插件2 JFormDesigner 使用教程2.1 新建JFormDesigner Form时的选项2.2 JFormDesigner Form界面布局2.3 JFormDesigner 组件2.3.1 Components基本组件2.3.2 Containers中间容器&#xff08;面板&#xff09;2.3.3 Windows顶级容器&#xff08;窗口&am…

给科研人的 ML 开源发布工具包

什么是开源发布工具包&#xff1f; 恭喜你的论文成功发表&#xff0c;这是一个巨大的成就&#xff01;你的研究成果将为学界做出贡献。 其实除了发表论文之外&#xff0c;你还可以通过发布研究的其他部分&#xff0c;如代码、数据集、模型等&#xff0c;来增加研究的可见度和采…

【从0上手cornerstone3D】如何加载nifti格式的文件

在线演示 支持加载的文件格式 .nii .nii.gz 代码实现 npm install cornerstonejs/nifti-volume-loader// ------------- 核心代码 Start------------------- // 注册一个nifti格式的加载器 volumeLoader.registerVolumeLoader("nifti",cornerstoneNiftiImageVolu…

Qt/C++编写视频监控系统83-自定义悬浮条信息

一、前言 一般视频控件上会给出个悬浮条&#xff0c;这个悬浮条用于显示分辨率或者一些用户期望看到的信息&#xff0c;一般常用的信息除了分辨率以外&#xff0c;还有帧率、封装格式、视频解码器名称、音频解码器名称、实时码率等&#xff0c;由于实际的场景不一样&#xff0…

el-date-picker默认结束为当前时分秒

在element ui中的日期时间选择组件中默认是00:00,现在需求是点击默认结束时间为当前时分秒&#xff0c;查了很多资料写的都不准确 需求&#xff1a;实现日期时间组件可选择当前日期&#xff0c;比如当前是2024年01月17号下午17&#xff1a;21 那选中时必须结束时间为17&#x…

页面数据类型为json,后端接受json数据

项目结构 依赖pom.xml <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework…

小白准备蓝桥杯之旅(c/c++b组)

前言&#xff1a;省赛获奖比例高达百分之60,只要比一半的人努力&#xff0c;你就能大概率获奖。 寒假做的3件事 1.稳基础 熟练掌握基础语法部分&#xff0c;c比c多个stl库优势&#xff0c;c语言的同学需要会实现c中stl库部分 2.刷真题 大概比赛前30天&#xff0c;坚持每天做…

Redis集群优化

文章目录 前言集群完整性问题集群带宽问题 前言 集群虽然具备高可用特性&#xff0c;能实现自动故障修复&#xff0c;但是如果使用不当&#xff0c;也会存在一些问题 集群完整性问题集群带宽问题数据倾泻问题客户端性能问题命令的集群兼容性问题Lua和事务问题 集群完整性问题…

低代码配置-属性配置面板设计

模块设计 tab项切换 组件基础属性组件数据属性组件事件属性表单属性 模块输出函数设计 tab切换函数 列表表单属性 数据来源&#xff1a; 调用接口时一次赋予&#xff0c;无需使用selectItem&#xff0c;如需使用&#xff0c;归入基础属性列表标题是否展示筛选区域 示例&am…

输入框输入关键字 下拉框的关键字高亮

直接上代码 //搜索框部分 <div><input v-modelkeyWord /><button clickseachFn>搜索</button> </div> //下拉框部分 <div><div v-html"item.name" v-foritem in droplist :keyitem.id></div> </div> <sc…

centos环境下安装nginx+简单使用nginx

参考&#xff1a; https://www.cnblogs.com/chaofanq/p/15022916.html Nginx安装使用教程 - 简书 1.安装 1.1 下载一下 nginx: download 选择稳定版本下载 1.2 上传到虚拟机 cd /usr/local/src/ 1.3 进入目录开始解压 tar -xvf nginx-1.24.0.tar.gz 1.4 安装 cd nginx…

我帮企业找市场|福田供应链企业走进佛山,刮起“两业融合”新旋风!

前言&#xff1a; 2023年以来&#xff0c;福田区锚定高质量发展首要任务&#xff0c;鼓实劲、出实招、求实效&#xff0c;继推出“万名干部助企行”“我帮企业找市场”“我帮企业找资金”等系列服务举措后&#xff0c;坚持系统、全面完善产业支持政策&#xff0c;打造产业发展最…

QT中操作word文档

QT中操作word文档&#xff1a; 参考如下内容&#xff1a; C(Qt) 和 Word、Excel、PDF 交互总结 Qt对word文档操作总结 QT中操作word文档 Qt/Windows桌面版提供了ActiveQt框架&#xff0c;用以为Qt和ActiveX提供完美结合。ActiveQt由两个模块组成&#xff1a; QAxContainer模…

SpringBoot整合MyBatis项目进行CRUD操作项目示例

文章目录 SpringBoot整合MyBatis项目进行CRUD操作项目示例1.1.需求分析1.2.创建工程1.3.pom.xml1.4.application.properties1.5.启动类 2.添加用户2.1.数据表设计2.2.pojo2.3.mapper2.4.service2.5.junit2.6.controller2.7.thymeleaf2.8.测试 3.查询用户3.1.mapper3.2.service3…