【问题标题】:ElasticsearchCrudRepository bulk insertion gives error - Validation Failed: 1: no requests addedElasticsearchCrudRepository 批量插入给出错误 - 验证失败:1:未添加请求
【发布时间】:2019-09-17 06:41:20
【问题描述】:

我在我的 Spring 项目中使用 ElasticsearchCrudRepository 将记录插入到弹性搜索中。单记录插入工作正常,但是当我尝试插入记录列表时,我面临弹性搜索的一些异常。下面是堆栈跟踪 -

org.elasticsearch.action.ActionRequestValidationException:验证 失败:1:没有添加请求;在 org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:29) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.action.bulk.BulkRequest.validate(BulkRequest.java:600) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:46) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.client.transport.TransportProxyClient.lambda$execute$0(TransportProxyClient.java:59) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:250) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:366) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) ~[elasticsearch-5.6.11.jar:5.6.11] 在 org.springframework.data.elasticsearch.core.ElasticsearchTemplate.bulkIndex(ElasticsearchTemplate.java:617) ~[spring-data-elasticsearch-3.0.10.RELEASE.jar:3.0.10.RELEASE] 在 org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.saveAll(AbstractElasticsearchRepository.java:185) ~[spring-data-elasticsearch-3.0.10.RELEASE.jar:3.0.10.RELEASE] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) ~[na:1.8.0_151] 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) ~[na:1.8.0_151] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) ~[na:1.8.0_151] 在 java.lang.reflect.Method.invoke(未知来源) ~[na:1.8.0_151] 在 org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE] 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.9.RELEASE.jar:5.0.9.RELEASE] 在 com.sun.proxy.$Proxy104.saveAll(Unknown Source) ~[na]

下面是我用来将数据插入弹性搜索的代码 -

public interface DataModelElasticRepository extends ElasticsearchRepository<BaseDataModel,String> {

}


@Service
public class DataModelServiceImpl implements DataModelService, Serializable {

    @Autowired
    private DataModelElasticRepository dataModelRepository;

    @Override
    public BaseDataModel save(BaseDataModel datamodel) {
        // TODO Auto-generated method stub
        return dataModelRepository.save(datamodel);
    }

    @Override
    public Iterable<BaseDataModel> save(Iterable<BaseDataModel> dataModelList) {
        return dataModelRepository.saveAll(dataModelList);
    }

}


public interface DataModelService {

    BaseDataModel save(BaseDataModel datamodel);

    Iterable<BaseDataModel> save(Iterable<BaseDataModel> dataModelList);
}

谁能告诉我我在这里做错了什么?谢谢。

【问题讨论】:

    标签: spring-boot elasticsearch spring-data-jpa


    【解决方案1】:

    我现在使用的是 HighLevelRestClient,而不是使用 ElasticSearchRepository。我遇到了下面给出的 ElasticSerachRepository 的一些问题 -

    Handling org.elasticsearch.client.transport.NoNodeAvailableException

    通过 HighLevelClient 可以轻松地批量插入请求。

    https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 2018-03-16
      • 1970-01-01
      • 2013-04-30
      • 2013-02-16
      • 2021-11-12
      相关资源
      最近更新 更多