英文:
Error at createIndex elasticsearch using ElasticsearchOperations. Why is the "BytesReference class was expected" exception happening?
问题
我使用了 org.elasticsearch:elasticsearch 版本 6.8,并且在连接方面我使用了 TransportClient。然后我决定升级到版本 7.6,由于 TransportClient 被弃用,我不得不通过 RestHighLevelClient 进行与 Elasticsearch 的连接。在这之后,在启动后出现了以下错误:
java.lang.IncompatibleClassChangeError: 找到接口 org.elasticsearch.common.bytes.BytesReference,但是预期为类
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();
}
}
我做错了什么?
英文:
I used org.elasticsearch:elasticsearch version 6.8 and for connectivity I used TransportClient. I then decided to upgrade to version 7.6 and since TransportClient is Deprecated, I had to use the connection to elastic via the RestHighLevelClient. After this, the following error appeared after the start:
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 appears on the index creation line:
elasticsearchOperations.deleteIndex(clazz);
elasticsearchOperations.createIndex(clazz, loadFromFileSetting(pathSetting, someParams));
I use the following config class for connection:
@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?
答案1
得分: 3
我想要补充Opster Elasticsearch Ninja的答案。这里描述的问题已经通过在你的gradle.build中实现"org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.2"来解决。之后,您应该将索引类型指示为"_doc",并确保您的Java客户端版本与您的Elasticsearch版本相匹配。
英文:
I would like to supplement Opster Elasticsearch Ninja`s answer. The problem described here has been solved by implementation "org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.2" in your gradle.build. After that you should indicate the index type as _doc and make sure that your java client version matches your Elasticsearch version.
答案2
得分: 1
问题已通过在Elasticsearch API中使用_doc
解决,因为在Elasticsearch 7.X版本中已弃用types
,仅允许使用_doc
类型以实现向后兼容,并将在Elasticsearch 8.X中完全移除。
有关移除类型的更多信息,请参阅Elasticsearch官方文档。
英文:
The issue was resolved by using the _doc
in the Elasticsearch API as types
are deprecated in Elasticsearch 7.X version and only _doc
type is allowed for backward compatibility purpose and will be totally removed in Elasticsearch 8.X.
More information on removal of types Elasticsearch official documentation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论