Reputation: 23
I try to write config for elasticsearchclient but i keep getting an error like this :
APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
co.elastic.clients.transport.rest_client.RestClientOptions.initialOptions(RestClientOptions.java:179)
The following method did not exist:
org.elasticsearch.client.RequestOptions$Builder.addHeader(Ljava/lang/String;Ljava/lang/String;)Lorg/elasticsearch/client/RequestOptions$Builder;
The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:
jar:file:/C:/Users/UtkuUslusoy/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/6.8.3/elasticsearch-rest-client-6.8.3.jar!/org/elasticsearch/client/RequestOptions$Builder.class
It was loaded from the following location:
file:/C:/Users/UtkuUslusoy/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/6.8.3/elasticsearch-rest-client-6.8.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RequestOptions$Builder
@Configuration
public class ElasticsearchConfiguration {
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConfiguration.class);
@Bean
public ElasticsearchClient elasticsearchClient(
@Value(value = "${com.**.**.core.configuration.**.mappingFile}") String mappingFile,
@Value(value = "${com.**.**.core.configuration.**.indexName}") String indexName,
@Value(value = "${com.**.**.core.configuration.**.hostName}") String hostName,
@Value(value = "${com.**.**.core.configuration.**.port}") Integer port) throws IOException {
final RestClient restClient = RestClient
.builder(new HttpHost(hostName, port))
.build();
final ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
final ElasticsearchClient client = new ElasticsearchClient(transport);
final InputStream stream = new ClassPathResource(mappingFile).getInputStream();
final CreateIndexRequest request = new CreateIndexRequest.Builder().index(indexName).withJson(stream).build();
try { client.indices().create(request); } catch (Throwable exception) { /* Intentionally left blank */ }
if (logger.isDebugEnabled()) logger.debug("Elasticsearch initialization complete");
return client;
}
}
Springboot Version :2.2.0.RELEASE
pom.xml:
<dependencies>
<!-- https://mvnrepository.com/artifact/co.elastic.clients/elasticsearch-java -->
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>7.17.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<!-- Needed only if you use the spring-boot Maven plugin -->
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-amqp -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.**.**</groupId>
<artifactId>aml-core</artifactId>
<version>${**.aml.version}</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<elasticsearch-version>7.17.2</elasticsearch-version>
</properties>
Upvotes: 1
Views: 3034
Reputation: 182
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.17.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/transport -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.17.2</version>
</dependency>
Add these to your pom.
Upvotes: 2