SpringBoot集成Elasticsearch8.x(9)|(RestClient curl实现Elasticsearch的操作)
文章目录
- SpringBoot集成Elasticsearch8.x(9)|(RestClient curl实现Elasticsearch的操作)
- @[TOC]
- 前言
- 一、DSL 介绍
- 二、初始化客户端
- 三、封装RestClient dsl执行
- 三、更新
- 1.实用script更新es中数据
- 总结
文章目录
- SpringBoot集成Elasticsearch8.x(9)|(RestClient curl实现Elasticsearch的操作)
- @[TOC]
- 前言
- 一、DSL 介绍
- 二、初始化客户端
- 三、封装RestClient dsl执行
- 三、更新
- 1.实用script更新es中数据
- 总结
章节
第一章链接: SpringBoot集成Elasticsearch7.x(1)|(增删改查功能实现)
第二章链接: SpringBoot集成Elasticsearch7.x(2)|(复杂查询)
第三章链接: SpringBoot集成Elasticsearch7.x(3)|(aggregations之指标聚合查询)
第四章链接: SpringBoot集成Elasticsearch7.x(4)|(aggregations之分桶聚合查询)
第五章链接: SpringBoot集成Elasticsearch7.x(5)|(term、match、match_phrase区别)
第六章链接: SpringBoot集成Elasticsearch8.x(6)|(新版本Java API Client使用)
第七章链接: SpringBoot集成Elasticsearch8.x(7)|(新版本Java API Client使用完整示例)
第八章链接:SpringBoot集成Elasticsearch8.x(8)|(新版本Java API Client的Painless语言脚本script使用)
第九章链接:SpringBoot集成Elasticsearch8.x(9)|(RestClient实现Elasticsearch的操作)
前言
Elasticsearch curl命令
-XGET一种请求方法
-d 标识以post形式传入参数 ,写在请求正文里面
?pretty=true 以格式的形式显示结果
curl -XGET http://localhost:9200/_cluster/health?pretty --查询elasticsearch的健康信息
curl -XGET http://localhost:9200/ --查询实例的相关信息
curl -XGET http://localhost:9200/_cluster/nodes/ --得到集群中节点的相关信息
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown --关闭整个集群
curl -XPOST http://localhost:9200/_cluster/nodes/aaaa/_shutdown --关闭集群中指定节点
curl -XPOST http://localhost:9200/test --创建名为test的索引
curl -XDELETE http://localhost:9200/test --删除名为test的索引
curl -XGET ‘http://10.10.110.2:19200/benlaitest/_search?pretty=true’ -d ‘{“query”:{“multi_match”:{“query”:“法国”,“fields”:[“firstname”,“lastname”]}}}’ --查询数据(匹配firstname和lastname)
curl http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard -d 我爱你中国
postman执行请求API:
http://10.10.110.160:9200/_cat/indices?v – Get请求 查看有多少索引
http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard --查看分词结果
一、DSL 介绍
Elasticsearch提供丰富且灵活的查询语言叫做DSL查询(Query DSL),它允许你构建更加复杂、强大的查询。DSL(Domain Specific Language特定领域语言)以JSON请求体的形式出现。
简单实用
//查询所有的商品
GET /product_index/product/_search
{"query": {"match_all": {}
}
//查询商品名称包含 milk 的商品,同时按照价格降序排序
GET /product_index/product/_search
{"query": {"match": {"product_name": "milk"}},"sort": [{"price": "desc"}]
}
二、初始化客户端
简单实用
@Beanprivate RestClient buildClient(EsClientProperties properties, HttpHost[] hostList) {int timeout = properties.getTimeout() == 0 ? 5000 : properties.getTimeout();String authorization = String.format("Basic