[英]NPE while executing Update By Query in Elasticsearch using Java
我在Spring Boot應用程序中使用Elasticsearch 2.4,並且需要使用Java API對遠程ES實例執行_update_by_query
請求。
我已經找到了解決這個問題的方法 ,但是就我的情況而言,我有一個NPE試圖執行.get()
函數。
ES的模塊包括:
compile 'org.elasticsearch.module:reindex:2.4.1'
這是我現在用於測試的代碼片段:
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
這是一個包裝好的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配置文件進行配置,因此只是為了方便。
NullPointerException
是由調用TransportProxyClient
的execute(...)
方法引起的:
final TransportActionNodeProxy<Request, Response> proxy = proxies.get(action); // no proxy found here
...
proxy.execute(node, request, listener); // NPE here
我想知道我是否錯過了某個步驟,或者自從上述問題以來用法是否已更改?
您缺少傳輸信息的配置。 它應該是TransportClient.builder().addPlugin(ReindexPlugin.class) .build().addTransportAddress(new InetSocketTransportAddress( InetAddress.getByName("127.0.0.1"), 9300));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.