@Test
public void directConnectionTest() throws IOException {
if (open.equals(“true”)) {
//创建索引
CreateIndexResponse response = directConnectionESClient.indices().create(c -> c.index(“direct_connection_index”));
log.info(response.toString());
}
else{
log.info(“es is closed”);
}
}
#### 账号密码连接`ES`
1. 设置:`ES` `Elasticsearch.yml`的`xpack.security.enabled`属性使用默认值`+` `xpack.security.http.ssl.enabled`设置为`false`
>
> 注意:若`xpack.security.enabled`属性为`false`,则`xpack.security.http.ssl.enabled`属性不生效,即相当于设置为`false`;所有以`xpack`开头的属性都不会生效
>
>
>
>
> `ES` `Elasticsearch.yml`的`xpack.security.http.ssl.enabled`:
> ● 默认`true`:必须使用`https://localhost:9200/`访问`ES`服务`+`启动`Kibana`服务会成功`+`需要使用账号连接`+`必须使用`HTTPS`连接
> ● 若为`false`:必须使用`http://localhost:9200/`访问`ES`服务`+`启动`Kibana`服务会失败+需要使用账号连接,但必须使用HTTP连接
>
>
>
2. 配置:`dev`目录`application-dal`中添加下列配置
elasticsearch配置
elasticsearch:
userName: #自己的账号名
password: #自己的密码
3. 添加:`ElasticSearchTest`类中添加下列代码`---`索引名必须小写`+`不能有空格
4. 运行:设置跳过测试`--->`手动运行/不跳过`--->`直接`install`,但不运行测试
@Resource(name = “accountConnectionESClient”)
ElasticsearchClient accountConnectionESClient;
@Test
public void accountConnectionTest() throws IOException {
if (open.equals(“true”)) {
//创建索引
CreateIndexResponse response = accountConnectionESClient.indices().create(c -> c.index(“account_connection_index”));
log.info(response.toString());
}
else{
log.info(“es is closed”);
}
}
#### 证书账号连接`ES`
1. 设置:`ES` `Elasticsearch.yml`的`xpack.security.enabled`和`xpack.security.http.ssl.enabled`配置项使用默认值
>
> 设置为`true`后,`ES`就走`https`,若`scheme`为`http`,则报`Unrecognized` SSL `message`错误
>
>
>
2. 配置:将`dev`目录`application-dal`中`elasticsearch.scheme`配置项改成`https`
3. 证书添加:终端输入`keytool -importcert -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts" -file "D:\computelTool\database\e