Search in sources :

Example 11 with SearchRequestBuilder

use of org.opensearch.action.search.SearchRequestBuilder in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectCountUniquely.

// ===================================================================================
// Select
// ======
@Override
protected int delegateSelectCountUniquely(final ConditionBean cb) {
    // #pending check response and cast problem
    final SearchRequestBuilder builder = client.prepareSearch(asEsIndex());
    final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
    if (esCb.getPreference() != null) {
        builder.setPreference(esCb.getPreference());
    }
    return (int) getSearchHits(esCb.build(builder).execute().actionGet(searchTimeout)).getTotalHits().value;
}
Also used : SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder)

Example 12 with SearchRequestBuilder

use of org.opensearch.action.search.SearchRequestBuilder in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectCountUniquely.

// ===================================================================================
// Select
// ======
@Override
protected int delegateSelectCountUniquely(final ConditionBean cb) {
    // #pending check response and cast problem
    final SearchRequestBuilder builder = client.prepareSearch(asEsIndex());
    final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
    if (esCb.getPreference() != null) {
        builder.setPreference(esCb.getPreference());
    }
    return (int) getSearchHits(esCb.build(builder).execute().actionGet(searchTimeout)).getTotalHits().value;
}
Also used : SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder)

Example 13 with SearchRequestBuilder

use of org.opensearch.action.search.SearchRequestBuilder in project fess by codelibs.

the class EsAbstractBehavior method delegateBulkRequest.

protected void delegateBulkRequest(final ConditionBean cb, Function<SearchHits, Boolean> handler) {
    final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()).setScroll(scrollForCursor).setSize(sizeForCursor);
    final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
    if (esCb.getPreference() != null) {
        builder.setPreference(esCb.getPreference());
    }
    esCb.request().build(builder);
    SearchResponse response = esCb.build(builder).execute().actionGet(scrollSearchTimeout);
    String scrollId = response.getScrollId();
    try {
        while (scrollId != null) {
            final SearchHits searchHits = getSearchHits(response);
            final SearchHit[] hits = searchHits.getHits();
            if (hits.length == 0) {
                break;
            }
            if (!handler.apply(searchHits)) {
                break;
            }
            response = client.prepareSearchScroll(scrollId).setScroll(scrollForDelete).execute().actionGet(scrollSearchTimeout);
            if (!scrollId.equals(response.getScrollId())) {
                deleteScrollContext(scrollId);
            }
            scrollId = response.getScrollId();
        }
    } finally {
        deleteScrollContext(scrollId);
    }
}
Also used : SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) SearchHit(org.opensearch.search.SearchHit) SearchHits(org.opensearch.search.SearchHits) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)13 SearchResponse (org.opensearch.action.search.SearchResponse)9 SearchHits (org.opensearch.search.SearchHits)9 SearchHit (org.opensearch.search.SearchHit)6 IllegalBehaviorStateException (org.dbflute.exception.IllegalBehaviorStateException)3 BulkRequestBuilder (org.opensearch.action.bulk.BulkRequestBuilder)3 BulkResponse (org.opensearch.action.bulk.BulkResponse)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 PostConstruct (javax.annotation.PostConstruct)1 PreDestroy (javax.annotation.PreDestroy)1 Resource (javax.annotation.Resource)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 ThreadUtil (org.codelibs.core.lang.ThreadUtil)1 Constants (org.codelibs.fess.Constants)1 Crawler (org.codelibs.fess.crawler.Crawler)1