Elasticsearch REST客户端MultiGet-GetResult始终为null

时间:2018-09-18 22:18:43

标签: java elasticsearch

我正在构建C:\Users\$folder\AppData\Local\**Google**\... 以验证Elasticsearch中是否存在记录。

这是我的方法:

MultiGetRequest

不幸的是,@Scheduled(cron = "${es.doSomething}") public List<Record> doSomething() { MultiGetRequest multiExistRequest = new MultiGetRequest(); someService.findAll().forEach(record -> { String id = record.get("id").asText(); multiExistRequest.add(new MultiGetRequest.Item("_all", "type", id) .fetchSourceContext(FetchSourceContext.FETCH_SOURCE) .storedFields("_none_")); }); BulkRequest bulkDeleteRequest = new BulkRequest(); final CountDownLatch existLatch = new CountDownLatch(multiExistRequest.getItems().size()); ActionListener<MultiGetResponse> existListener = new ActionListener<MultiGetResponse>() { @Override public void onResponse(MultiGetResponse responses) { responses.forEach(response -> { assert response.getFailure() == null; GetResponse getResponse = response.getResponse(); if (getResponse.isExists()) { bulkDeleteRequest.add(new DeleteRequest(response.getIndex(), response.getType(), response.getId())); } existLatch.countDown(); }); } @Override public void onFailure(Exception e) { // TODO -- add retry logic LOGGER.error(e.getMessage(), e); existLatch.countDown(); } }; client.multiGetAsync(multiExistRequest, existListener); try { existLatch.await(); } catch (InterruptedException e) { LOGGER.error("Latch was interrupted", e); } // Do more stuff... } 抛出了getResponse.isExists(),而底层的NullPointerException为空。为什么会这样呢?似乎请求成功,并返回200:

GetResult

我正在使用Elasticsearch高级REST客户端6.3.2。

0 个答案:

没有答案