准备工作:
1:环境搭建
Elasticsearch:https://www.elastic.co/cn/downloads/elasticsearch
kibana:https://www.elastic.co/cn/downloads/kibana
!!!注意:版本需要一致
安装分词插件,分别解压下载好的三个文件,运行elasticsearch/bin/elasticsearch.bat文件,浏览器访问: http://localhost:9200/ 会得到相应的版本信息
安装kibana 下载过后直接解压:kibana/bin/kibana.bat 执行批量启动脚本
访问localhost:5601 可以查看控制台页面
开始配置:
=========>>>>>>>>\elasticsearch-7.3.0\config\elasticsearch.yml
cluster.name : 集群名称,默认是elasticsearch
node.name: node-es #节点名称
node.master: true #这个属性表示节点是否具有成为主节点的资格。
node.data: true #这个属性表示节点是否存储数据
network.host: 0.0.0.0 # 设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0,绑定这台机器的任何一个ip。
index.number_of_shards: 5 #设置默认索引分片个数,默认为5片
index.number_of_replicas: 1 #设置默认副本为1
path.work: /path/to/work # 设置临时文件的存储路径,默认是es根目录下的work文件夹。
path.logs: /path/to/logs # 设置日志文件的存储路径,默认是es根目录下的logs文件夹
network.publish_host: 192.168.0.103 # 设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址。(最好设置本地ip,其实不设置影响也不大)
http.port: 9200 #设置对外服务的http端口,默认为9200。
http.cors.enabled: true
http.cors.allow-origin: "*"
以上配置的是主要参数:其他配置可以参考地址:https://www.cnblogs.com/zenan/p/10983580.html
============>>>>>>>\kibana-7.3.0-windows-x86_64\config\kibana.yml
server.host: "192.168.0.103" //其实可以不用修改的,只是简单说明一下,后面有用处
===========================================================================================
开始整合springboot:
在pom.xml中引入spring-boot-starter-data-elasticsearch
application.yml文件中
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.1.1</version>
</dependency>
-------------------------------------------
连接kibana配置:
@Bean
public RestHighLevelClient client() {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("192.168.0.103", 9200, "http") #ip要跟kibana.yml里面配置一样
//这里如果要用client去访问其他节点,就添加进去
));
return client;
}
------------------------------------------------
@GetMapping("/order/getById")
public Map<String, Object> getOrder() {
EsConfig esConfig = new EsConfig();
RestHighLevelClient client = esConfig.client();
GetRequest getRequest = new GetRequest("lib", "test", "1");
Map map = new HashMap();
GetResponse response = null;
try {
response = client.get(getRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
if (response.isExists()) {
map.put("success", true);
map.put("data", response.getSource());
} else {
map.put("success", false);
}
return map;
}
=======================================
kibana入手操作: https://blog.youkuaiyun.com/qq_27950699/article/details/99695778