本文整理汇总了Java中org.elasticsearch.search.aggregations.AbstractAggregationBuilder类的典型用法代码示例。如果您正苦于以下问题:Java AbstractAggregationBuilder类的具体用法?Java AbstractAggregationBuilder怎么用?Java AbstractAggregationBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractAggregationBuilder类属于org.elasticsearch.search.aggregations包,在下文中一共展示了AbstractAggregationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeCountAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* Create count aggregation.
*
* @param field The count function
* @return AggregationBuilder use to count result
*/
private AbstractAggregationBuilder makeCountAgg(MethodField field) {
// Cardinality is approximate DISTINCT.
if ("DISTINCT".equals(field.getOption())) {
if (field.getParams().size() == 1) {
return AggregationBuilders.cardinality(field.getAlias()).field(field.getParams().get(0).value.toString());
} else {
Integer precision_threshold = (Integer) (field.getParams().get(1).value);
return AggregationBuilders.cardinality(field.getAlias()).precisionThreshold(precision_threshold).field(field.getParams().get(0).value.toString());
}
}
String fieldName = field.getParams().get(0).value.toString();
// In case of count(*) we use '_index' as field parameter to count all documents
if ("*".equals(fieldName)) {
return AggregationBuilders.count(field.getAlias()).field("_index");
} else {
return AggregationBuilders.count(field.getAlias()).field(fieldName);
}
}
示例2: mapResults
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
public <T> AggregatedPage<T> mapResults(SearchResult response, Class<T> clazz, List<AbstractAggregationBuilder> aggregations, Pageable pageable) {
LinkedList<T> results = new LinkedList<>();
for (SearchResult.Hit<JsonObject, Void> hit : response.getHits(JsonObject.class)) {
if (hit != null) {
results.add(mapSource(hit.source, clazz));
}
}
String scrollId = null;
if (response instanceof ExtendedSearchResult) {
scrollId = ((ExtendedSearchResult) response).getScrollId();
}
return new AggregatedPageImpl<>(results, pageable, response.getTotal(), response.getAggregations(), scrollId);
}
示例3: collectBucketKeys
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
@Override
public ListenableFuture<List<String>> collectBucketKeys(String[] indices, QueryBuilder query,
AbstractAggregationBuilder... aggregations) {
SearchRequestBuilder elasticRequest =
client.prepareSearch(indices)
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setTypes(SPAN)
.setQuery(query)
.setSize(0);
for (AbstractAggregationBuilder aggregation : aggregations) {
elasticRequest.addAggregation(aggregation);
}
return transform(toGuava(elasticRequest.execute()), BucketKeys.INSTANCE);
}
示例4: collectBucketKeys
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
@Override
protected ListenableFuture<List<String>> collectBucketKeys(String[] indices,
QueryBuilder query, AbstractAggregationBuilder... aggregations) {
SearchSourceBuilder elasticQuery = new SearchSourceBuilder().query(query).size(0);
for (AbstractAggregationBuilder aggregation : aggregations) {
elasticQuery.aggregation(aggregation);
}
Call searchRequest = http.newCall(new Request.Builder().url(lenientSearch(indices, SPAN))
.post(RequestBody.create(APPLICATION_JSON, elasticQuery.toString()))
.tag("search-spansAggregations").build());
return new CallbackListenableFuture<List<String>>(searchRequest) {
List<String> convert(ResponseBody responseBody) throws IOException {
Set<String> result = collectValuesNamed(JsonReader.of(responseBody.source()), "key");
return Util.sortedList(result);
}
}.enqueue();
}
示例5: makeFieldAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* Create aggregation according to the SQL function.
* @param field SQL function
* @param parent parentAggregation
* @return AggregationBuilder represents the SQL function
* @throws SqlParseException in case of unrecognized function
*/
public AbstractAggregationBuilder makeFieldAgg(MethodField field, AbstractAggregationBuilder parent) throws SqlParseException {
groupMap.put(field.getAlias(), new KVValue("FIELD", parent));
switch (field.getName().toUpperCase()) {
case "SUM":
return AggregationBuilders.sum(field.getAlias()).field(field.getParams().get(0).toString());
case "MAX":
return AggregationBuilders.max(field.getAlias()).field(field.getParams().get(0).toString());
case "MIN":
return AggregationBuilders.min(field.getAlias()).field(field.getParams().get(0).toString());
case "AVG":
return AggregationBuilders.avg(field.getAlias()).field(field.getParams().get(0).toString());
case "STATS":
return AggregationBuilders.stats(field.getAlias()).field(field.getParams().get(0).toString());
case "TOPHITS":
return makeTopHitsAgg(field);
case "COUNT":
groupMap.put(field.getAlias(), new KVValue("COUNT", parent));
return makeCountAgg(field);
default:
throw new SqlParseException("the agg function not to define !");
}
}
示例6: makeCountAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* Create count aggregation.
* @param field The count function
* @return AggregationBuilder use to count result
*/
private AbstractAggregationBuilder makeCountAgg(MethodField field) {
// Cardinality is approximate DISTINCT.
if ("DISTINCT".equals(field.getOption())) {
return AggregationBuilders.cardinality(field.getAlias()).precisionThreshold(40000).field(field.getParams().get(0).value.toString());
}
String fieldName = field.getParams().get(0).value.toString();
// In case of count(*) we use '_index' as field parameter to count all documents
if ("*".equals(fieldName)) {
return AggregationBuilders.count(field.getAlias()).field("_index");
}
else {
return AggregationBuilders.count(field.getAlias()).field(fieldName);
}
}
示例7: makeTopHitsAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* TOPHITS查询
*
* @param field
* @return
*/
private AbstractAggregationBuilder makeTopHitsAgg(MethodField field) {
TopHitsBuilder topHits = AggregationBuilders.topHits(field.getAlias());
List<KVValue> params = field.getParams();
for (KVValue kv : params) {
switch (kv.key) {
case "from":
topHits.setFrom((int) kv.value);
break;
case "size":
topHits.setSize((int) kv.value);
break;
default:
topHits.addSort(kv.key, SortOrder.valueOf(kv.value.toString().toUpperCase()));
break;
}
}
return topHits;
}
示例8: explanFields
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
private void explanFields(SearchRequestBuilder request, List<Field> fields, AggregationBuilder<?> groupByAgg) throws SqlParseException {
for (Field field : fields) {
if (field instanceof MethodField) {
AbstractAggregationBuilder makeAgg = aggMaker.makeFieldAgg((MethodField) field, groupByAgg);
if (groupByAgg != null) {
groupByAgg.subAggregation(makeAgg);
}
else {
request.addAggregation(makeAgg);
}
} else if (field instanceof Field) {
request.addField(field.getName());
} else {
throw new SqlParseException("it did not support this field method " + field);
}
}
}
示例9: makeTopHitsAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* TOPHITS查询
*
* @param field
* @return
*/
private AbstractAggregationBuilder makeTopHitsAgg(MethodField field) {
String alias = gettAggNameFromParamsOrAlias(field);
TopHitsBuilder topHits = AggregationBuilders.topHits(alias);
List<KVValue> params = field.getParams();
for (KVValue kv : params) {
switch (kv.key) {
case "from":
topHits.setFrom((int) kv.value);
break;
case "size":
topHits.setSize((int) kv.value);
break;
case "alias":
break;
default:
topHits.addSort(kv.key, SortOrder.valueOf(kv.value.toString().toUpperCase()));
break;
}
}
return topHits;
}
示例10: buildAggregation
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
private AbstractAggregationBuilder buildAggregation() {
TermsBuilder rootBuilder = null;
TermsBuilder termsBuilder = null;
for (String field : getParameter().getNesting()) {
if (null == termsBuilder) {
termsBuilder = AggregationBuilders.terms(Utils.sanitizeFieldForAggregation(field)).field(field);
} else {
TermsBuilder tempBuilder = AggregationBuilders.terms(Utils.sanitizeFieldForAggregation(field)).field(field);
termsBuilder.subAggregation(tempBuilder);
termsBuilder = tempBuilder;
}
termsBuilder.size(0);
if (null == rootBuilder) {
rootBuilder = termsBuilder;
}
}
if (!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) {
assert termsBuilder != null;
termsBuilder.subAggregation(Utils.buildCardinalityAggregation(getParameter().getUniqueCountOn()));
}
return rootBuilder;
}
示例11: getElasticsearchStatisticsAggregations
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
protected List<AbstractAggregationBuilder> getElasticsearchStatisticsAggregations(StatisticsAggregation agg) {
List<AbstractAggregationBuilder> aggs = new ArrayList<>();
for (String propertyName : getPropertyNames(agg.getFieldName())) {
String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName);
String aggName = createAggregationName(agg.getAggregationName(), visibilityHash);
ExtendedStatsAggregationBuilder statsAgg = AggregationBuilders.extendedStats(aggName);
statsAgg.field(propertyName);
aggs.add(statsAgg);
}
return aggs;
}
示例12: getElasticsearchPercentilesAggregations
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
protected List<AbstractAggregationBuilder> getElasticsearchPercentilesAggregations(PercentilesAggregation agg) {
String propertyName = getSearchIndex().addVisibilityToPropertyName(getGraph(), agg.getFieldName(), agg.getVisibility());
String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName);
String aggName = createAggregationName(agg.getAggregationName(), visibilityHash);
PercentilesAggregationBuilder percentilesAgg = AggregationBuilders.percentiles(aggName);
percentilesAgg.field(propertyName);
if (agg.getPercents() != null && agg.getPercents().length > 0) {
percentilesAgg.percentiles(agg.getPercents());
}
return Collections.singletonList(percentilesAgg);
}
示例13: addAggregation
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* Add an aggregation definition.
*/
public PercolateSourceBuilder addAggregation(AbstractAggregationBuilder aggregationBuilder) {
if (aggregations == null) {
aggregations = new ArrayList<>();
}
aggregations.add(aggregationBuilder);
return this;
}
示例14: toXContent
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (docBuilder != null) {
docBuilder.toXContent(builder, params);
}
if (queryBuilder != null) {
builder.field("query");
queryBuilder.toXContent(builder, params);
}
if (size != null) {
builder.field("size", size);
}
if (sorts != null) {
builder.startArray("sort");
for (SortBuilder sort : sorts) {
builder.startObject();
sort.toXContent(builder, params);
builder.endObject();
}
builder.endArray();
}
if (trackScores != null) {
builder.field("track_scores", trackScores);
}
if (highlightBuilder != null) {
highlightBuilder.toXContent(builder, params);
}
if (aggregations != null) {
builder.field("aggregations");
builder.startObject();
for (AbstractAggregationBuilder aggregation : aggregations) {
aggregation.toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}
示例15: makeTopHitsAgg
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; //导入依赖的package包/类
/**
* TOPHITS查询
*
* @param field
* @return
*/
private AbstractAggregationBuilder makeTopHitsAgg(MethodField field) {
String alias = gettAggNameFromParamsOrAlias(field);
TopHitsAggregationBuilder topHits = AggregationBuilders.topHits(alias);
List<KVValue> params = field.getParams();
String[] include = null;
String[] exclude = null;
for (KVValue kv : params) {
switch (kv.key) {
case "from":
topHits.from((int) kv.value);
break;
case "size":
topHits.size((int) kv.value);
break;
case "include":
include = kv.value.toString().split(",");
break;
case "exclude":
exclude = kv.value.toString().split(",");
break;
case "alias":
case "nested":
case "reverse_nested":
case "children":
break;
default:
topHits.sort(kv.key, SortOrder.valueOf(kv.value.toString().toUpperCase()));
break;
}
}
if (include != null || exclude != null) {
topHits.fetchSource(include, exclude);
}
return topHits;
}