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?