private Stream<MessageSearchIndex.SearchResult> transformResponseToUidStream(SearchResponse searchResponse) { return Iterators.toStream(searchResponse.getHits().iterator()) .map(this::extractContentFromHit) .filter(Optional::isPresent) .map(Optional::get); }
SearchResponse response = client.prepareSearch().execute().actionGet(); SearchHits hits = response.getHits(); Iterator<SearchHit> iterator = hits.iterator(); Map<String, SearchHit> distinctObjects = new HashMap<String,SearchHit>(); while (iterator.hasNext()) { SearchHit searchHit = (SearchHit) iterator.next(); Map<String, Object> source = searchHit.getSource(); if(source.get("name") != null){ distinctObjects.put(source.get("name").toString(),source); } }
public ESCursorResult(SearchResponse response, int batchSize, int keepAliveSeconds) { super(response.getHits().iterator(), batchSize, keepAliveSeconds); this.scrollId = response.getScrollId(); }
protected void runNextScroll() { SearchResponse response = ESAuditBackend.this.runNextScroll(scrollId, TimeValue.timeValueSeconds(keepAliveSeconds)); cursor = response.getHits().iterator(); end = !cursor.hasNext(); }
private Iterator<SearchHit> fetchNextHits() { SearchResponse response = client.prepareSearch(indexName) .setTypes(objType) .setFrom(from.intValue()) .setSize(recsToRead.intValue()) .setQuery(QueryBuilders.queryString(queryString)) .execute() .actionGet(); return response.getHits().iterator(); }
@Override public boolean hasNext() { if(allowedRemaining <= 0) return false; if(hits.hasNext()) return true; timing.start("scroll"); scrollResponse = client.prepareSearchScroll(scrollResponse.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet(); timing.stop("scroll"); hits = convertFunc.apply(scrollResponse.getHits().iterator()); return hits.hasNext(); }
public boolean hasNext() { if (iterator != null && !iterator.hasNext()) { scrollResp = index.getClient().prepareSearchScroll(scrollResp.getScrollId()) .setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).execute().actionGet(); if (scrollResp.getHits().getHits().length == 0) { iterator = null; } else { iterator = scrollResp.getHits().iterator(); } } if (iterator != null && iterator.hasNext()) { return true; } else { return false; } }
private void fetchNextHits() { if (scrollId == null) { LOG.info("Running initial scroll with timeout "+scrollTimeout); SearchRequestBuilder request = split.initialScrollRequest(client, scroll, requestSize); SearchResponse response = request.execute().actionGet(); this.scrollId = response.getScrollId(); LOG.info("Got scroll ID "+scrollId); // Do we need to call fetchNextHits() again here? Or does // the initial request also itself contain the first set // of hits for the scroll? // // fetchNextHits(); } else { // LOG.info("Running query for scroll ID "+scrollId+" with timeout "+scrollTimeout); SearchScrollRequestBuilder request = split.scrollRequest(client, scroll, scrollId); SearchResponse response = request.execute().actionGet(); this.scrollId = response.getScrollId(); // LOG.info("Got scroll ID "+scrollId); this.hitsItr = response.getHits().iterator(); } }
SearchResponse searchResponse = client.search(searchRequest); SearchHits hits = searchResponse.getHits(); Iterator<SearchHit> hitsIt = hits.iterator();
SearchResponse searchResponse = client.search(searchRequest); SearchHits hits = searchResponse.getHits(); Iterator<SearchHit> hitsIt = hits.iterator();
public QueryIterator(FilterBuilder filter, int startFrom, int scrollSize, long maxSize, Client client, Function<Iterator<SearchHit>, Iterator<? extends E>> convertFunc, Boolean refresh, TimingAccessor timing, String... indices) { this.client = client; this.allowedRemaining = maxSize; this.convertFunc = convertFunc; this.timing = timing; if (refresh) client.admin().indices().prepareRefresh(indices).execute().actionGet(); this.timing.start("scroll"); scrollResponse = client.prepareSearch(indices) .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filter)) .setFrom(startFrom) .setScroll(new TimeValue(60000)) .setSize(maxSize < scrollSize ? (int) maxSize : scrollSize) .execute().actionGet(); this.timing.stop("scroll"); hits = convertFunc.apply(scrollResponse.getHits().iterator()); }
final Iterator<SearchHit> iterator = response.getHits().iterator(); while (iterator.hasNext()) { final SearchHit hit = iterator.next();
final Iterator<SearchHit> iterator = response.getHits().iterator(); while (iterator.hasNext()) { final SearchHit hit = iterator.next();
final Iterator<SearchHit> iterator = response.getHits().iterator(); while (iterator.hasNext()) { final SearchHit hit = iterator.next();
final Iterator<SearchHit> iterator = response.getHits().iterator(); while (iterator.hasNext()) { final SearchHit hit = iterator.next();
public KeyIterator(ElasticsearchIndex index) { this.index = index; MatchAllQueryBuilder query = QueryBuilders.matchAllQuery(); scrollResp = index.getClient().prepareSearch(index.getIndex()).setTypes(index.getType()) .addFields(new String[] {}).setSearchType(SearchType.SCAN) .setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).setQuery(query) .setSize(ElasticsearchIndex.SCROLLSIZE).execute().actionGet(); scrollResp = index.getClient().prepareSearchScroll(scrollResp.getScrollId()) .setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).execute().actionGet(); iterator = scrollResp.getHits().iterator(); }
final SearchResponse response = dataContext.getElasticSearchClient().search(searchRequest); final Iterator<SearchHit> iterator = response.getHits().iterator(); while (iterator.hasNext()) { final SearchHit hit = iterator.next();