@Override public boolean hasNext() { if (hits.isEmpty()) { SearchScrollRequestBuilder esRequest = esClient.prepareSearchScroll(scrollId) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)); Collections.addAll(hits, esRequest.get().getHits().getHits()); } return !hits.isEmpty(); }
@Test public void fail_to_search_bad_query() { try { es.client().prepareSearchScroll("unknown").get(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class); assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'"); } }
@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareSearchScroll("scrollId").get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareSearchScroll("scrollId").get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
public List<String> findAllViewUuids() { SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW) .addSort("_doc", SortOrder.ASC) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)) .setFetchSource(false) .setSize(100) .setQuery(matchAllQuery()); SearchResponse response = esSearch.get(); List<String> result = newArrayList(); while (true) { List<SearchHit> hits = newArrayList(response.getHits()); for (SearchHit hit : hits) { result.add(hit.getId()); } String scrollId = response.getScrollId(); response = esClient.prepareSearchScroll(scrollId) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)) .get(); // Break condition: No hits are returned if (response.getHits().getHits().length == 0) { esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get(); break; } } return result; } }
firstTableResponse = client.prepareSearchScroll(firstTableResponse.getScrollId()).setScroll(new TimeValue(600000)).get(); else finishedWithFirstTable = true;
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); SearchResponse response = es.client().prepareSearch(FakeIndexDefinition.INDEX) .setScroll(TimeValue.timeValueMinutes(1)) .get(); logTester.clear(); es.client().prepareSearchScroll(response.getScrollId()).get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void no_trace_logs() { logTester.setLevel(LoggerLevel.DEBUG); SearchResponse response = es.client().prepareSearch(FakeIndexDefinition.INDEX) .setScroll(TimeValue.timeValueMinutes(1)) .get(); logTester.clear(); es.client().prepareSearchScroll(response.getScrollId()).get(); assertThat(logTester.logs()).isEmpty(); }
break; searchResponse = client.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(5)).get(); if (hits.length == 0) { client.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); tc.prepareSearchScroll(scrollId).get(); } finally { ctx.close(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "worf"); tc.prepareSearchScroll(searchRes.getScrollId()).get(); Assert.fail(); } catch (Exception e) { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); searchRes = tc.prepareSearch("starfleet").setTypes("ships").setScroll(TimeValue.timeValueMinutes(5)).get(); SearchResponse scrollRes = tc.prepareSearchScroll(searchRes.getScrollId()).get(); Assert.assertEquals(0, scrollRes.getFailedShards()); } finally {
try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); tc.prepareSearchScroll(scrollId).get(); } finally { ctx.close(); try { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "worf"); tc.prepareSearchScroll(searchRes.getScrollId()).get(); Assert.fail(); } catch (Exception e) { tc.threadPool().getThreadContext().putHeader("sg_impersonate_as", "nagilum"); searchRes = tc.prepareSearch("starfleet").setTypes("ships").setScroll(TimeValue.timeValueMinutes(5)).get(); SearchResponse scrollRes = tc.prepareSearchScroll(searchRes.getScrollId()).get(); Assert.assertEquals(0, scrollRes.getFailedShards()); } finally {
@Override public boolean hasNext() { if (hits.isEmpty()) { SearchScrollRequestBuilder esRequest = esClient.prepareSearchScroll(scrollId) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)); Collections.addAll(hits, esRequest.get().getHits().getHits()); } return !hits.isEmpty(); }
/** * Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data. * * @return */ @ApiOperation(value = "Get deployment status events from a given date.", notes = "Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") }) @RequestMapping(value = "/status/scroll", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasAuthority('ADMIN')") public ScrollJsonResult get(@RequestParam String scrollId) { SearchResponse response = monitorDao.getClient().prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(5)).get(); return convert(response); }
public List<String> findAllViewUuids() { SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW) .addSort("_doc", SortOrder.ASC) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)) .setFetchSource(false) .setSize(100) .setQuery(matchAllQuery()); SearchResponse response = esSearch.get(); List<String> result = newArrayList(); while (true) { List<SearchHit> hits = newArrayList(response.getHits()); for (SearchHit hit : hits) { result.add(hit.getId()); } String scrollId = response.getScrollId(); response = esClient.prepareSearchScroll(scrollId) .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)) .get(); // Break condition: No hits are returned if (response.getHits().getHits().length == 0) { esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get(); break; } } return result; } }
private void deleteIndexType(final String fromIndex, final String fromType) { final SearchRequestBuilder builder = client.prepareSearch(fromIndex).setTypes(fromType).setScroll("1m"); SearchResponse searchResponse = builder.get(); SearchHit[] hits = searchResponse.getHits().getHits(); for (SearchHit hit : hits) client.prepareDelete(hit.index(), hit.type(), hit.id()).get(); while (hits.length != 0) { searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()).setScroll("1m").get(); hits = searchResponse.getHits().getHits(); for (SearchHit hit : hits) client.prepareDelete(hit.index(), hit.type(), hit.id()).get(); } }
firstTableResponse = client.prepareSearchScroll(firstTableResponse.getScrollId()).setScroll(new TimeValue(600000)).get(); else finishedWithFirstTable = true;
break; searchResponse = client.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(5)).get(); if (hits.length == 0) { client.nativeClient().prepareClearScroll().addScrollId(scrollId).get();