ElasticsearchCrudRepository批量插入产生错误-验证失败:1:未添加任何请求

时间:2019-04-28 11:31:14

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

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

  

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(未知来源)〜[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);
}

有人可以让我知道我在做什么错吗?谢谢。

1 个答案:

答案 0 :(得分:0)

我现在正在使用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