有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Java客户端创建ElasticSearch映射时发生AbstractMethodError

我使用的是SpringDataElasticSearch2.1.12。使用弹性搜索2.4.4发布

我有以下代码:

elasticsearchTemplate.createIndex(indexName);
elasticsearchTemplate.addAlias(alias);
elasticsearchTemplate.putMapping(MyElasticEntity.class);  //FAILS HERE!

我的实体是:

@Document(indexName = "psp", type = "payouts")
public class MyElasticEntity {

    @Id
    String id;

    UUID payoutId;

    // more fields of type UUID, enum, String, Instant and Long. Nothing unusual.

    @Version
    Long version;
}

我的代码在上面的putMapping中失败,原因是:

Caused by: java.lang.AbstractMethodError: null at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:552) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:530) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:729) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:398) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:229) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:172) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:85) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE] at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.getPersistentEntityFor(ElasticsearchTemplate.java:1094) ~[spring-data-elasticsearch-2.1.12.RELEASE.jar:na] at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.putMapping(ElasticsearchTemplate.java:183) ~[spring-data-elasticsearch-2.1.12.RELEASE.jar:na] at psp.elasticsearch.ESReindexingResource.reindexPayouts(ESReindexingResource.java:60) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_172] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_172] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_172] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_172] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 86 common frames omitted

似乎使用的实现是org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext类型,它确实定义了createPersistentProperty()实现

通过谷歌搜索,我发现有人建议我有不兼容版本的库。我怀疑这就是原因,但似乎找不到问题所在

有人建议在我的pom文件中包含spring-data-commons,但没有成功(可能是因为我添加了错误的版本-它已经存在了,通过可传递依赖关系)

如果我用curl命令创建映射,然后只添加文档,它就可以工作了,因此我的java代码(与我共享的代码一样简单)或依赖项肯定出了问题

你知道如何修复或更好地调试它吗


共 (0) 个答案