Import dependencies:
<properties>
<java.version>1.8</java.version>
<elasticsearch.version>7.4.2</elasticsearch.version>
</properties>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.2</version>
</dependency>
Focus on:
<elasticsearch.version>7.4.2</elasticsearch.version>
Ensure that the version is consistent, the cause of the problem will be described below
Configuration class:
@Configuration
public class MyElasticsearchConfig {
@Bean
public RestHighLevelClient esRestClient() {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("192.168.200.134", 9200, "http")));
//没有集群不用指定多个
// new HttpHost("localhost", 9201, "http"))
return client;
}
}
test:
@Autowired
private RestHighLevelClient client;
@Test
public void contextLoads() {
System.out.println(client);
}
question:
The following line of configuration is to control version consistency
<elasticsearch.version>7.4.2</elasticsearch.version>
Just retest