2

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.

A module for ES included:

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:

@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.

The NullPointerException is caused by invoking the execute(...) method of the 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?

1 Answer 1

4

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));

Sign up to request clarification or add additional context in comments.

3 Comments

What version of elasticsearch and reindex are you using, please? I get the error "TransportClient.builder() cannot be resolved".
I am using ES 2.xx
Ok, thanks. Just a hint for those who'd use version 5.5.0 or similar: The plugin has to be added as a second parameter in PreBuiltTransportClient's constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.