use of org.bedework.calfacade.indexing.IndexStatsResponse in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method getIndexStats.
@Override
public IndexStatsResponse getIndexStats(final String indexName) {
final IndexStatsResponse resp = new IndexStatsResponse(indexName);
if (indexName == null) {
return errorReturn(resp, "indexName must be provided");
}
final QueryBuilder qb = new FilteredQueryBuilder(null, FilterBuilders.matchAllFilter());
// 1 minute
final int timeoutMillis = 60000;
final TimeValue tv = new TimeValue(timeoutMillis);
final int batchSize = 100;
final Client cl = getClient(resp);
if (cl == null) {
return resp;
}
SearchResponse scrollResp = cl.prepareSearch(indexName).setSearchType(SearchType.SCAN).setScroll(tv).setQuery(qb).setSize(batchSize).execute().actionGet();
// Scroll until no hits are returned
while (true) {
for (final SearchHit hit : scrollResp.getHits().getHits()) {
resp.incProcessed();
final String dtype = hit.getType();
if (dtype.equals(docTypeEvent)) {
final EventInfo entity = (EventInfo) makeEntity(resp, hit, null);
if (entity == null) {
errorReturn(resp, "Unable to make doc for " + hit.sourceAsString());
continue;
}
final BwEvent ev = entity.getEvent();
if (ev instanceof BwEventAnnotation) {
final BwEventAnnotation ann = (BwEventAnnotation) ev;
if (ann.testOverride()) {
resp.incOverrides();
}
}
if (ev.getRecurring()) {
resp.incRecurring();
}
if (ev.getRecurrenceId() == null) {
resp.incMasters();
} else {
resp.incInstances();
}
} else {
resp.getStats().inc(docToType.getOrDefault(dtype, unreachableEntities));
}
}
scrollResp = cl.prepareSearchScroll(scrollResp.getScrollId()).setScroll(tv).execute().actionGet();
// Break condition: No hits are returned
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
return resp;
}
use of org.bedework.calfacade.indexing.IndexStatsResponse in project bw-calendar-engine by Bedework.
the class BwIndexCtl method indexStats.
@Override
public IndexStatsResponse indexStats(final String indexName) {
try {
final IndexStatsResponse resp = getIndexApp().getIndexStats(indexName);
info(resp.toString());
return resp;
} catch (final Throwable t) {
final IndexStatsResponse resp = new IndexStatsResponse("Failed");
resp.setStatus(failed);
resp.setMessage(t.getLocalizedMessage());
return resp;
}
}
Aggregations