elasticsearch
下载和安装
官网下载
- docker 下载
1
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.4.3
- 启动
1
docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" ce2b9dc7fe85
设置相关参数
- 设置跨域以及ip地址
1
2
3http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 127.0.0.1- 设置用户名和密码
1
.\elasticsearch-reset-password --username elastic -i
常见的Restful请求操作
名词解释
索引(相当于mysql的数据库)
类型(相当于mysql的表)
文档(相当于mysql的行)
字段(相当于mysql的列)
相关restful请求接口
新增 PUT
- 索引 article
- 4个分片 1个副本
1 | http://127.0.0.1:9200/article |
- 新增数据 mappings
1 | put http://127.0.0.1:9200/article/_mappings |
- 查询GET
1 | http://localhost:9200/_cat/indices //查询当前所有的索引 |
1 | http://127.0.0.1:9200/article/_mappings //查询索引详情 |
1 | http://localhost:9200/article/_search //查询内容 |
1 | { |
- 删除 DELETE
1 | localhost:9200/article?pretty |
- 传入数据
1 | localhost:9200/articl/_doc |
- 查询文档
1 | POST http://localhost:9200/article/_search?q=title:标题 |
简单整合
- 依赖
1 | <dependency> |
- 配置
1 | spring: |
- 映射实体类
1 |
|
- 接口映射 Repository
1 |
|
- crud
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 SimpleMw's Blog!