本文整理汇总了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();
}
示例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();
}
}
示例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();
}
示例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();
}