Search in sources :

Example 1 with DocMeta

use of org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectList.

@Override
protected <RESULT extends ENTITY> List<RESULT> delegateSelectList(final ConditionBean cb, final Class<? extends RESULT> entityType) {
    // #pending check response
    final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()).setTypes(asEsSearchType());
    final int from;
    final int size;
    if (cb.isFetchScopeEffective()) {
        from = cb.getPageStartIndex();
        size = cb.getFetchSize();
    } else {
        from = 0;
        size = 10;
    }
    builder.setFrom(from);
    builder.setSize(size);
    final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
    if (esCb.getPreference() != null) {
        builder.setPreference(esCb.getPreference());
    }
    esCb.request().build(builder);
    final SearchResponse response = esCb.build(builder).execute().actionGet(searchTimeout);
    final EsPagingResultBean<RESULT> list = new EsPagingResultBean<>(builder);
    final SearchHits searchHits = response.getHits();
    searchHits.forEach(hit -> {
        final Map<String, Object> source = hit.getSource();
        final RESULT entity = createEntity(source, entityType);
        final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
        docMeta.id(hit.getId());
        docMeta.version(hit.getVersion());
        list.add(entity);
    });
    list.setPageSize(size);
    list.setAllRecordCount((int) searchHits.getTotalHits());
    list.setCurrentPageNumber(cb.getFetchPageNumber());
    list.setTook(response.getTookInMillis());
    list.setTotalShards(response.getTotalShards());
    list.setSuccessfulShards(response.getSuccessfulShards());
    list.setFailedShards(response.getFailedShards());
    list.setAggregation(response.getAggregations());
    return list;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) DocMeta(org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta) SearchHits(org.elasticsearch.search.SearchHits)

Example 2 with DocMeta

use of org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectBulk.

protected <RESULT extends ENTITY> void delegateSelectBulk(final ConditionBean cb, final EntityRowHandler<List<RESULT>> handler, final Class<? extends RESULT> entityType) {
    assertCBStateValid(cb);
    assertObjectNotNull("entityRowHandler", handler);
    assertSpecifyDerivedReferrerEntityProperty(cb, entityType);
    assertObjectNotNull("entityRowHandler", handler);
    delegateBulkRequest(cb, searchHits -> {
        List<RESULT> list = new ArrayList<>();
        searchHits.forEach(hit -> {
            final Map<String, Object> source = hit.getSource();
            final RESULT entity = createEntity(source, entityType);
            final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
            docMeta.id(hit.getId());
            docMeta.version(hit.getVersion());
            list.add(entity);
        });
        handler.handle(list);
        return !handler.isBreakCursor();
    });
}
Also used : DocMeta(org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta) ArrayList(java.util.ArrayList)

Example 3 with DocMeta

use of org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectCursor.

@Override
protected <RESULT extends ENTITY> void delegateSelectCursor(final ConditionBean cb, final EntityRowHandler<RESULT> handler, final Class<? extends RESULT> entityType) {
    delegateBulkRequest(cb, searchHits -> {
        searchHits.forEach(hit -> {
            if (handler.isBreakCursor()) {
                return;
            }
            final Map<String, Object> source = hit.getSource();
            final RESULT entity = createEntity(source, entityType);
            final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
            docMeta.id(hit.getId());
            docMeta.version(hit.getVersion());
            handler.handle(entity);
        });
        return !handler.isBreakCursor();
    });
}
Also used : DocMeta(org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta)

Aggregations

DocMeta (org.codelibs.fess.es.log.allcommon.EsAbstractEntity.DocMeta)3 ArrayList (java.util.ArrayList)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchHits (org.elasticsearch.search.SearchHits)1