本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder.order方法的典型用法代码示例。如果您正苦于以下问题:Java TermsAggregationBuilder.order方法的具体用法?Java TermsAggregationBuilder.order怎么用?Java TermsAggregationBuilder.order使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder
的用法示例。
在下文中一共展示了TermsAggregationBuilder.order方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: termsAgg
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; //导入方法依赖的package包/类
private AggregationBuilder termsAgg(MethodField field) throws SqlParseException {
String aggName = gettAggNameFromParamsOrAlias(field);
TermsAggregationBuilder terms = AggregationBuilders.terms(aggName);
String value = null;
for (KVValue kv : field.getParams()) {
value = kv.value.toString();
switch (kv.key.toLowerCase()) {
case "field":
terms.field(value);
break;
case "size":
terms.size(Integer.parseInt(value));
break;
case "shard_size":
terms.shardSize(Integer.parseInt(value));
break;
case "min_doc_count":
terms.minDocCount(Integer.parseInt(value));
break;
case "missing":
terms.missing(value);
break;
case "order":
if ("asc".equalsIgnoreCase(value)) {
terms.order(BucketOrder.key(true));
} else if ("desc".equalsIgnoreCase(value)) {
terms.order(BucketOrder.key(false));
} else {
throw new SqlParseException("order can only support asc/desc " + kv.toString());
}
break;
case "alias":
case "nested":
case "reverse_nested":
case "children":
break;
case "execution_hint":
terms.executionHint(value);
break;
default:
throw new SqlParseException("terms aggregation err or not define field " + kv.toString());
}
}
return terms;
}
示例2: termsAgg
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; //导入方法依赖的package包/类
private AggregationBuilder termsAgg(MethodField field) throws SqlParseException {
String aggName = gettAggNameFromParamsOrAlias(field);
TermsAggregationBuilder terms = AggregationBuilders.terms(aggName);
String value = null;
for (KVValue kv : field.getParams()) {
value = kv.value.toString();
switch (kv.key.toLowerCase()) {
case "field":
terms.field(value);
break;
case "size":
terms.size(Integer.parseInt(value));
break;
case "shard_size":
terms.shardSize(Integer.parseInt(value));
break;
case "min_doc_count":
terms.minDocCount(Integer.parseInt(value));
break;
case "missing":
terms.missing(value);
break;
case "order":
if ("asc".equalsIgnoreCase(value)) {
terms.order(Terms.Order.term(true));
} else if ("desc".equalsIgnoreCase(value)) {
terms.order(Terms.Order.term(false));
} else {
throw new SqlParseException("order can only support asc/desc " + kv.toString());
}
break;
case "alias":
case "nested":
case "reverse_nested":
case "children":
break;
default:
throw new SqlParseException("terms aggregation err or not define field " + kv.toString());
}
}
return terms;
}
示例3: getBucketsQueries
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; //导入方法依赖的package包/类
/**
* Get's buckets queries from {@link GroupBy} item in URL.
*
* @param groupBy
* groupBy instance
* @param entityType
* entity type
* @param pagination
* pagination information
* @return list of fields
* @throws ODataApplicationException
* if any error occurred
*/
protected List<AggregationBuilder> getBucketsQueries(GroupBy groupBy,
ElasticEdmEntityType entityType, Pagination pagination)
throws ODataApplicationException {
int size = pagination.getSkip() + pagination.getTop();
Map<String, Boolean> orders = pagination.getOrderBy().stream()
.collect(toMap(Sort::getProperty, order -> order.getDirection() == Direction.ASC));
List<String> properties = getProperties(groupBy);
reverse(properties);
// Last because of reverse
String lastProperty = properties.remove(0);
String queryField = getQueryField(lastProperty, entityType);
TermsAggregationBuilder groupByQuery = terms(lastProperty).field(queryField).size(size)
.shardSize(getShardSize(size));
getMetricsAggQueries(getAggregations(groupBy.getApplyOption()))
.forEach(groupByQuery::subAggregation);
List<Order> queryOrders = getQueryOrders(queryField, orders);
if (!queryOrders.isEmpty()) {
groupByQuery.order(queryOrders);
}
for (String property : properties) {
queryField = getQueryField(property, entityType);
groupByQuery = terms(property).field(queryField).size(size)
.subAggregation(groupByQuery);
Boolean termOrder = orders.remove(queryField);
if (termOrder != null) {
groupByQuery.order(Terms.Order.term(termOrder));
}
}
// Fields in $orderby are not same as $groupby fields!
if (!orders.isEmpty()) {
throw new ODataApplicationException(
"Ordering only by fields in $groupby or $aggregation options is allowed.",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
}
// For now only one 'groupby' is supported and returned in the list
return Arrays.asList(groupByQuery);
}
示例4: populateBuffer
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; //导入方法依赖的package包/类
@Override
protected void populateBuffer() {
if (lastDate == null) {
lastDate = new Date();
}
String formattedLastDate = ISODateTimeFormat.dateTimeNoMillis().print(
lastDate.getTime());
LOG.info("{} Populating buffer with nextFetchDate <= {}", logIdprefix,
formattedLastDate);
QueryBuilder queryBuilder = QueryBuilders.rangeQuery("nextFetchDate")
.lte(formattedLastDate);
if (filterQuery != null) {
queryBuilder = boolQuery().must(queryBuilder).filter(
QueryBuilders.queryStringQuery(filterQuery));
}
SearchRequestBuilder srb = client.prepareSearch(indexName)
.setTypes(docType).setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(queryBuilder).setFrom(0).setSize(0).setExplain(false);
TermsAggregationBuilder aggregations = AggregationBuilders
.terms("partition").field(partitionField).size(maxBucketNum);
TopHitsAggregationBuilder tophits = AggregationBuilders.topHits("docs")
.size(maxURLsPerBucket).explain(false);
// sort within a bucket
if (StringUtils.isNotBlank(bucketSortField)) {
FieldSortBuilder sorter = SortBuilders.fieldSort(bucketSortField)
.order(SortOrder.ASC);
tophits.sort(sorter);
}
aggregations.subAggregation(tophits);
// sort between buckets
if (StringUtils.isNotBlank(totalSortField)) {
MinAggregationBuilder minBuilder = AggregationBuilders.min(
"top_hit").field(totalSortField);
aggregations.subAggregation(minBuilder);
aggregations.order(BucketOrder.aggregation("top_hit", true));
}
if (sample) {
DiversifiedAggregationBuilder sab = new DiversifiedAggregationBuilder(
"sample");
sab.field(partitionField).maxDocsPerValue(maxURLsPerBucket);
sab.shardSize(maxURLsPerBucket * maxBucketNum);
sab.subAggregation(aggregations);
srb.addAggregation(sab);
} else {
srb.addAggregation(aggregations);
}
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-preference.html
// _shards:2,3
if (shardID != -1) {
srb.setPreference("_shards:" + shardID);
}
// dump query to log
LOG.debug("{} ES query {}", logIdprefix, srb.toString());
timeStartESQuery = System.currentTimeMillis();
isInESQuery.set(true);
srb.execute(this);
}