use of org.codelibs.fess.crawler.util.AccessResultCallback in project fess-crawler by codelibs.
the class EsDataService method iterate.
@Override
public void iterate(final String sessionId, final AccessResultCallback<EsAccessResult> callback) {
SearchResponse response = null;
while (true) {
if (response == null) {
response = getClient().get(c -> c.prepareSearch(index).setTypes(type).setScroll(new TimeValue(scrollTimeout)).setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery(SESSION_ID, sessionId))).setSize(scrollSize).execute());
} else {
final String scrollId = response.getScrollId();
response = getClient().get(c -> c.prepareSearchScroll(scrollId).setScroll(new TimeValue(scrollTimeout)).execute());
}
final SearchHits searchHits = response.getHits();
if (searchHits.getHits().length == 0) {
break;
}
for (final SearchHit searchHit : searchHits) {
final Map<String, Object> source = searchHit.getSourceAsMap();
final EsAccessResult accessResult = BeanUtil.copyMapToNewBean(source, EsAccessResult.class, option -> {
option.converter(new EsTimestampConverter(), timestampFields).excludeWhitespace();
option.exclude(EsAccessResult.ACCESS_RESULT_DATA);
});
@SuppressWarnings("unchecked") final Map<String, Object> data = (Map<String, Object>) source.get(EsAccessResult.ACCESS_RESULT_DATA);
if (data != null) {
accessResult.setAccessResultData(new EsAccessResultData(data));
}
callback.iterate(accessResult);
}
}
}
Aggregations