Search in sources :

Example 1 with IndexStatsResponse

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;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) FilteredQueryBuilder(org.elasticsearch.index.query.FilteredQueryBuilder) BwEvent(org.bedework.calfacade.BwEvent) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FilteredQueryBuilder(org.elasticsearch.index.query.FilteredQueryBuilder) TransportClient(org.elasticsearch.client.transport.TransportClient) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexStatsResponse(org.bedework.calfacade.indexing.IndexStatsResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 2 with IndexStatsResponse

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;
    }
}
Also used : IndexStatsResponse(org.bedework.calfacade.indexing.IndexStatsResponse)

Aggregations

IndexStatsResponse (org.bedework.calfacade.indexing.IndexStatsResponse)2 BwEvent (org.bedework.calfacade.BwEvent)1 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 Client (org.elasticsearch.client.Client)1 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)1 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 FilteredQueryBuilder (org.elasticsearch.index.query.FilteredQueryBuilder)1 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 TermsQueryBuilder (org.elasticsearch.index.query.TermsQueryBuilder)1 SearchHit (org.elasticsearch.search.SearchHit)1