当前位置: 首页>>代码示例>>Java>>正文


Java CountRequestBuilder.setQuery方法代码示例

本文整理汇总了Java中org.elasticsearch.action.count.CountRequestBuilder.setQuery方法的典型用法代码示例。如果您正苦于以下问题:Java CountRequestBuilder.setQuery方法的具体用法?Java CountRequestBuilder.setQuery怎么用?Java CountRequestBuilder.setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.count.CountRequestBuilder的用法示例。


在下文中一共展示了CountRequestBuilder.setQuery方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: count

import org.elasticsearch.action.count.CountRequestBuilder; //导入方法依赖的package包/类
@Override
public Long count(Class clazz, @Nullable QueryBuilder queryBuilder) {
    CountRequestBuilder countRequestBuilder = client.prepareCount(getIndexName());
    if (queryBuilder != null) {
        countRequestBuilder.setQuery(queryBuilder);
    }


    String typeName = MappingProcessor.getIndexTypeName(clazz);
    countRequestBuilder.setTypes(typeName);

    if (logger.isDebugEnabled()) {
        String queryStr = "";
        if (queryBuilder != null) {
            queryStr = queryBuilder.buildAsBytes().toUtf8();
        }
        logger.debug("Count for class: {}, query: {}", clazz.getSimpleName(), queryStr);
    }

    return countRequestBuilder.get().getCount();
}
 
开发者ID:kzwang,项目名称:elasticsearch-osem,代码行数:22,代码来源:ElasticSearchSearcherImpl.java

示例2: count

import org.elasticsearch.action.count.CountRequestBuilder; //导入方法依赖的package包/类
/**
 * http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html
 * @param query
 * @param type
 * @return
 */
public <T> long count(SearchCriteria query, String type) throws SearchException {
       Timer.Context timer = searchMetrics.indexTimer(type, "count");
	try {
		CountRequestBuilder request = client.prepareCount(indexName).setTypes(type);
		if(query!=null && query.getQuery()!=null){
			request.setQuery(query.getQuery());
		}
           searchMetrics.indexIncr(type, "count");
		return request.execute().actionGet().getCount();
	} catch (Exception e) {
           searchMetrics.failedIncr(type, "count", e);
           logger.error("count Error. ", e);
           throw new SearchException("count Error. typeName="+type, e);
	}finally {
           timer.stop();
       }
   }
 
开发者ID:yamingd,项目名称:argo,代码行数:24,代码来源:ElasticSearchTemplate.java

示例3: count

import org.elasticsearch.action.count.CountRequestBuilder; //导入方法依赖的package包/类
@Override
public CountResponse count(String[] indices, String... types) {
    CountRequestBuilder countRequestBuilder = esClient.getClient().prepareCount(indices);
    if (types != null && types.length > 0) {
        countRequestBuilder.setTypes(types);
    }
    countRequestBuilder.setQuery(this.queryBuilder);
    return countRequestBuilder.execute().actionGet();
}
 
开发者ID:alien4cloud,项目名称:elasticsearch-mapping-parent,代码行数:10,代码来源:QueryHelper.java

示例4: count

import org.elasticsearch.action.count.CountRequestBuilder; //导入方法依赖的package包/类
@Override
public long count(Set<String> types, String query, Set<String> filterIds, EzSecurityToken userToken)
        throws TException {
    final Stopwatch watch = LoggingUtils.createStopWatch();
    CountRequestBuilder requestBuilder = client.prepareCount(indexName);

    final VisibilityFilterConfig filterConfig =
            new VisibilityFilterConfig(VISIBILITY_FIELD, EnumSet.of(Permission.DISCOVER));

    final ScriptFilterBuilder visibilityFilter = getVisibilityFilter(userToken, filterConfig);

    if (!types.isEmpty()) {
        requestBuilder = requestBuilder.setTypes(types.toArray(new String[types.size()]));
    }
    if (!filterIds.isEmpty()) {
        if (StringUtils.isNotEmpty(query)) {
            requestBuilder = requestBuilder.setQuery(
                    QueryBuilders.filteredQuery(
                            QueryBuilders.boolQuery().must(parseQuery(query)).must(
                                    QueryBuilders.idsQuery().addIds(
                                            filterIds.toArray(new String[filterIds.size()]))), visibilityFilter));
        } else {
            requestBuilder = requestBuilder.setQuery(
                    QueryBuilders.filteredQuery(
                            QueryBuilders.idsQuery().addIds(filterIds.toArray(new String[filterIds.size()])),
                            visibilityFilter));
        }
    } else if (StringUtils.isNotEmpty(query)) {
        requestBuilder = requestBuilder.setQuery(QueryBuilders.filteredQuery(parseQuery(query), visibilityFilter));
    } else {
        requestBuilder = requestBuilder.setQuery(
                QueryBuilders.filteredQuery(
                        QueryBuilders.matchAllQuery(), visibilityFilter));
    }

    final CountResponse response = requestBuilder.get();

    LoggingUtils.stopAndLogStopWatch(logger, watch, "Count");

    return response.getCount();
}
 
开发者ID:ezbake,项目名称:ezelastic,代码行数:42,代码来源:ElasticClient.java


注:本文中的org.elasticsearch.action.count.CountRequestBuilder.setQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。