简体   繁体   English

使用Java在Elasticsearch中执行按查询更新时的NPE

[英]NPE while executing Update By Query in Elasticsearch using Java

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. 我在Spring Boot应用程序中使用Elasticsearch 2.4,并且需要使用Java API对远程ES实例执行_update_by_query请求。
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. 我已经找到了解决这个问题的方法 ,但是就我的情况而言,我有一个NPE试图执行.get()函数。

A module for ES included: 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

Here's a wrapped Client bean: 这是一个包装好的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());
}

Wrapper is needed to allow configuring via Spring Boot configuration files, so it's just for convenience. 需要包装器以允许通过Spring Boot配置文件进行配置,因此只是为了方便。

The NullPointerException is caused by invoking the execute(...) method of the TransportProxyClient : NullPointerException是由调用TransportProxyClientexecute(...)方法引起的:

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? 我想知道我是否错过了某个步骤,或者自从上述问题以来用法是否已更改?

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)); 它应该是TransportClient.builder().addPlugin(ReindexPlugin.class) .build().addTransportAddress(new InetSocketTransportAddress( InetAddress.getByName("127.0.0.1"), 9300));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM