使用Java在Elasticsearch中执行更新查询时NPE [英] NPE while executing Update By Query in Elasticsearch using Java

查看:599
本文介绍了使用Java在Elasticsearch中执行更新查询时NPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring Boot应用程序中使用了Elasticsearch 2.4,我需要执行 _update_by_query

我发现在这个问题上完成此任务的方法,但是对于我的情况,我有一个NPE试图执行 .get()函数。

I'm using Elasticsearch 2.4 in a Spring Boot application and I need to execute _update_by_query request to the remote ES instance using Java API.
I've found the way to accomplish this task at this question, but as for my case I've got an NPE trying to execute the .get() function.

ES的模块包括:

compile 'org.elasticsearch.module:reindex:2.4.1'

这是我现在用于测试的代码片段:

Here's a code snippet I use for testing right now:

UpdateByQueryRequestBuilder request = UpdateByQueryAction.INSTANCE.newRequestBuilder(clientWrapper.getClient());  // clientWrapper is a bean and gets injected
Script script = new Script(
  "ctx._source.testName = \"TEST HAPPENED\"",
  ScriptService.ScriptType.INLINE, null, null);

request.source().setTypes("type");

BulkIndexByScrollResponse r = request
  .source(ES_INDEX_NAME)
  .filter(QueryBuilders.termQuery("testId", "Sk9lzQHdJT0"))
  .script(script)
  .get();  // the exception gets raised here

这是一个包裹的客户端 bean:

Here's a wrapped Client bean:

@Bean
public ClientWrapper elasticsearchClient(Client client) {
return new ClientWrapper(
  TransportClient.builder()
    .addPlugin(ReindexPlugin.class)  // here's the plugin that is supposed to work
    .settings(client.settings())
    .build());
}

需要包装器才能通过Spring Boot配置文件进行配置,因此只适用于

Wrapper is needed to allow configuring via Spring Boot configuration files, so it's just for convenience.

NullPointerException 是由调用 execute(...)
TransportProxyClient 的方法:

final TransportActionNodeProxy<Request, Response> proxy = proxies.get(action);  // no proxy found here
... 
proxy.execute(node, request, listener);  // NPE here

我想知道我是否错过了一些步骤,或者自从提到的问题以来,使用情况发生了变化以上?

I wonder if I missed some step or maybe the usage has changed since the question mentioned above?

推荐答案

你缺少运输信息的配置。它应该是
TransportClient.builder()。addPlugin(ReindexPlugin.class)
.build()。addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName(127.0。 0.1),9300));

you are missing config for transport information. It should be TransportClient.builder().addPlugin(ReindexPlugin.class) .build().addTransportAddress(new InetSocketTransportAddress( InetAddress.getByName("127.0.0.1"), 9300));

这篇关于使用Java在Elasticsearch中执行更新查询时NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆