Answer the question
In order to leave comments, you need to log in
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)
elasticsearchOperations.deleteIndex(clazz);
elasticsearchOperations.createIndex(clazz, loadFromFileSetting(pathSetting, someParams));
@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();
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question