P
P
poznavaka2020-04-04 16:18:58
Java
poznavaka, 2020-04-04 16:18:58

Why is the createIndex elasticsearch error using ElasticsearchOperations?

I used org.elasticsearch:elasticsearch version 6.8 and used TransportClient to connect. Then I decided to upgrade to version 7.6 , and since the TransportClient is Deprecated, I was forced to use the connection to elastic via RestHighLevelClient. After that, after starting, the following error appeared:

java.lang.IncompatibleClassChangeError: Found interface org.elasticsearch.common.bytes.BytesReference, but class was expected
at org.elasticsearch.client.RequestConverters.createEntity(RequestConverters.java:689)
at org.elasticsearch.client.RequestConverters.createEntity(RequestConverters.java:684)
at org.elasticsearch.client.IndicesRequestConverters.createIndex(IndicesRequestConverters.java:128)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1760)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1734)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1696)
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:191)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.createIndex(ElasticsearchRestTemplate.java:1248)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.createIndex(ElasticsearchRestTemplate.java:1256)

It occurs on the index creation line:
elasticsearchOperations.deleteIndex(clazz);
elasticsearchOperations.createIndex(clazz, loadFromFileSetting(pathSetting, someParams));


I use the following config class to connect:

@Slf4j
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.project.elastic.repository")
public class ElasticConfig extends AbstractElasticsearchConfiguration {

    @Value("${spring.data.elastic.url}")
    private String url;

    @Override
    public RestHighLevelClient elasticsearchClient() {
        return RestClients.create(ClientConfiguration.create(url)).rest();
    }
}


What am I doing wrong? Judging by the error, it's not at all about creating an index ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
poznavaka, 2020-04-06
@poznavaka

The problem described here is solved by adding implementation "org.elasticsearch.client:elasticsearch-rest-high-levell-client:7.6.2". in gradle.build. After that, you should specify the index type as _doc and make sure your java client version matches the version of Elasticsearch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question