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


Java TermsBuilder类代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder的典型用法代码示例。如果您正苦于以下问题:Java TermsBuilder类的具体用法?Java TermsBuilder怎么用?Java TermsBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TermsBuilder类属于org.elasticsearch.search.aggregations.bucket.terms包,在下文中一共展示了TermsBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createResponse

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
/**
 * create a SearchResponse with the main search query (from the FileResource /api/_search/files)
 *
 * @param query
 * @param aggregation
 * @return
 */
private SearchResponse createResponse(String query, TermsBuilder aggregation) {
    SearchResponse response;
    if (StringUtils.isNotEmpty(query)) {
        response = elasticsearchTemplate.getClient().prepareSearch(Constants.INDEX_NAME)
            .setTypes(Constants.TYPE_NAME)
            //ici nous utilisons la même querybuilder que dans la recherche principale pour obtenir justement
            //le même filtrage sur les versions courantes
            .setQuery(Queries.constructQuery(query))
            .addAggregation(aggregation)
            .execute().actionGet();
    } else {
        response = elasticsearchTemplate.getClient().prepareSearch(Constants.INDEX_NAME)
            .setTypes(Constants.TYPE_NAME)
            .addAggregation(aggregation)
            .execute().actionGet();
    }
    return response;
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:26,代码来源:CustomSearchRepositoryImpl.java

示例2: aggregateByRawField

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
@Override
public Map<String, Long> aggregateByRawField(String field, String filtre) {

    TermsBuilder aggregation = AggregationBuilders.terms("top_" + field)
        .field(field + ".raw")
        .size(0)// le résultat n'est pas complet si on ne précise pas la taille, 0 : infini
        // (voir : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_size)
        .order(Terms.Order.aggregation("_count", false));

    SearchResponse response = createResponse(filtre, aggregation);

    Map<String, Aggregation> results = response.getAggregations().asMap();
    StringTerms topField = (StringTerms) results.get("top_" + field);

    //sur l'ensemble des buckets, triés par ordre décroissant sur le nombre de documents
    // on retourne une Map (LinkedHashMap) pour conserver l'ordre avec la clé, le nom du champ (exemple version), et la valeur, le nombre de docs
    //exemple :
    // "trunk" -> 34012
    // "branche_1" -> 35800
    return topField.getBuckets()
        .stream()
        .sorted(Comparator.comparing(Terms.Bucket::getDocCount).reversed())
        .collect(
            Collectors.toMap(bucket -> bucket.getKeyAsString(), bucket -> bucket.getDocCount(), (v1, v2) -> v1, LinkedHashMap::new
            ));

}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:28,代码来源:CustomSearchRepositoryImpl.java

示例3: parse

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
public TermsBuilder parse(List<GroupingElement> elements, QueryState state){
	List<Column> groups = new ArrayList<Column>();
	for(GroupingElement grouping : elements){
		for(Set<Expression> expressions : grouping.enumerateGroupingSets()){
			for(Expression e : expressions)	groups.add((Column) e.accept(this, state) );
		}
	}
	
	// to find case sensitive group by definitions which ES needs
	for(Column groupby : groups){
		if(groupby.getOp() != Operation.NONE){
			state.addException("Can not use function '"+groupby.getAggName()+"' as GROUP BY, please use an alias to group by a function");
			return null;
		}
	}
	Heading.fixColumnReferences(state.originalSql()+";", "group by.+", "\\W", groups);
	
	for(Column g : groups){
		Column s = state.getHeading().getColumnByLabel(g.getAggName());
		if(s == null ){
			state.addException("Group by '"+g.getColumn()+"' not defined in SELECT");
		}else{
			// add column from select to this group (when referenced through an alias)
			g.setColumn(s.getColumn());
		}
	}
	return buildAggregationQuery(groups, 0, state);
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:29,代码来源:GroupParser.java

示例4: buildAggregationQuery

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
/**
 * Adds aggregations recursively
 * All metric columns are added to last aggregation
 * @param aggs
 * @param index
 * @param metrics
 * @return
 */
private TermsBuilder buildAggregationQuery(List<Column> aggs, int index, QueryState state){
	Column agg = aggs.get(index);
	TermsBuilder result = null;
	if(aggs.get(index).getOp() == Operation.NONE){
		result = AggregationBuilders.terms(agg.getAggName()).field(agg.getColumn());
		result.size(state.getIntProp(Utils.PROP_FETCH_SIZE, 10000));
	}
	if(index < aggs.size() - 1) result.subAggregation(buildAggregationQuery(aggs, index+1, state));
	else addMetrics(result, state.getHeading(), true); 
	return result;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:20,代码来源:GroupParser.java

示例5: addDistinctAggregation

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
public TermsBuilder addDistinctAggregation(QueryState state){
	List<Column> distinct = new ArrayList<Column>();
	for(Column s : state.getHeading().columns()){
		if(s.getOp() == Operation.NONE && s.getCalculation() == null) distinct.add(s);
	}
	return buildAggregationQuery(distinct, 0, state);
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:8,代码来源:GroupParser.java

示例6: makeGroupAgg

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
/**
 * 分组查的聚合函数
 * 
 * @param field
 * @return
 * @throws SqlParseException
 */
public AggregationBuilder<?> makeGroupAgg(Field field) throws SqlParseException {
	if (field instanceof MethodField) {
		return makeRangeGroup((MethodField) field);
	} else {
		TermsBuilder termsBuilder = AggregationBuilders.terms(field.getName()).field(field.getName());
		groupMap.put(field.getName(), new KVValue("KEY", termsBuilder));
		return termsBuilder;
	}
}
 
开发者ID:lane-cn,项目名称:elasticsql,代码行数:17,代码来源:AggMaker.java

示例7: getNodeTimeseriesStatistics

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
@Override
public List<NodeTimeseriesStatistics> getNodeTimeseriesStatistics(String tenantId, Criteria criteria, long interval) {
    String index = client.getIndex(tenantId);
    if (!refresh(index)) {
        return null;
    }

    AvgBuilder avgBuilder = AggregationBuilders
            .avg("avg")
            .field(ElasticsearchUtil.ACTUAL_FIELD);

    TermsBuilder componentsBuilder = AggregationBuilders
            .terms("components")
            .field("componentType")
            .size(criteria.getMaxResponseSize())
            .subAggregation(avgBuilder);

    DateHistogramBuilder histogramBuilder = AggregationBuilders
            .dateHistogram("histogram")
            .interval(interval)
            .field(ElasticsearchUtil.TIMESTAMP_FIELD)
            .subAggregation(componentsBuilder);

    BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, NodeDetails.class);
    SearchRequestBuilder request = getNodeDetailsRequest(index, criteria, query, 0)
            .addAggregation(histogramBuilder);

    SearchResponse response = getSearchResponse(request);
    DateHistogram histogram = response.getAggregations().get("histogram");

    return histogram.getBuckets().stream()
            .map(AnalyticsServiceElasticsearch::toNodeTimeseriesStatistics)
            .collect(Collectors.toList());
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:35,代码来源:AnalyticsServiceElasticsearch.java

示例8: createStringSearchBuilder

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
private SearchRequestBuilder createStringSearchBuilder(Collection<FieldInfo> fields) {
	SearchRequestBuilder builder = client.prepareSearch(indexName);
	for(FieldInfo info : fields) {
		TermsBuilder tokenBuilder = AggregationBuilders.terms(TERMS_AGG + info.getFullPath())
				.field(info.getFullPath())
				.minDocCount(props.getStringTokenMinOccurent())
				.size(props.getStringTokenLimit());
		builder.addAggregation(createNestedIfNecessary(info, tokenBuilder));

		ValueCountBuilder countBuilder = AggregationBuilders.count(VALUE_COUNT_AGG + info.getFullPath()).field(info.getFullPath());
		QueryBuilder filter = new BoolQueryBuilder().filter(new ExistsQueryBuilder(info.getFullPath()));
		FilterAggregationBuilder filterBuilder = AggregationBuilders.filter(FILTER_AGG + info.getFullPath()).filter(filter).subAggregation(countBuilder);
		builder.addAggregation(createNestedIfNecessary(info, filterBuilder));
	}
	builder.setSize(ZERO_ITEMS);
	return builder;
}
 
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:18,代码来源:FieldAnalyzer.java

示例9: SimpleAggregationBuilder

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
public SimpleAggregationBuilder(PB parentBuilder, TermsBuilder terms, String field, Integer size) {
	super(parentBuilder);
	if(size!=null){
		terms.size(size);
	}
	if(StringUtils.isNotBlank(field)){
		terms.field(field);
	}
	terms.order(Terms.Order.count(false));//COUNT_DESC
	this.aggsBuilder = terms;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:12,代码来源:SimpleSearchQueryBuilder.java

示例10: computeDocuments

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
private void computeDocuments(Credentials credentials, //
		Company[] companies, String[] companyIds) {

	ElasticClient elastic = Start.get().getElasticClient();
	String alias = elastic.toAlias(credentials.backendId(), DOCUMENT_TYPE);

	BoolQueryBuilder query = QueryBuilders.boolQuery()//
			.must(QueryBuilders.termsQuery(COMPANY_ID, companyIds));

	TermsBuilder aggBuilder = AggregationBuilders.terms("documents")//
			.field(COMPANY_ID).include(companyIds)//
			.subAggregation(AggregationBuilders.terms("waiting")//
					.field(STATUS).include(statuses));

	Terms agg = (Terms) elastic.prepareSearch()//
			.setIndices(alias).setTypes(DOCUMENT_TYPE)//
			.setQuery(query)//
			.addAggregation(aggBuilder)//
			.setSize(0)//
			.get()//
			.getAggregations()//
			.get("documents");

	for (Company company : companies) {
		Bucket bucket = agg.getBucketByKey(company.id);
		if (bucket != null) {
			Terms agg2 = (Terms) bucket.getAggregations().get("waiting");
			bucket = agg2.getBucketByKey(CLASSIFIED_STATUS);
			company.docsToAnalyze = bucket == null ? 0 : bucket.getDocCount();
			bucket = agg2.getBucketByKey(ANALYZED_STATUS);
			company.docsToProcess = bucket == null ? 0 : bucket.getDocCount();
		}
	}

}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:36,代码来源:TooleeResource.java

示例11: computeNotifications

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
private void computeNotifications(Credentials credentials, //
		Company[] companies, String[] companyIds) {

	ElasticClient elastic = Start.get().getElasticClient();
	String alias = elastic.toAlias(credentials.backendId(), NOTIFICATION_TYPE);
	String mainRole = getMainRole(credentials);

	BoolQueryBuilder query = QueryBuilders.boolQuery()//
			.must(QueryBuilders.termsQuery(COMPANY_ID, companyIds));

	BoolQueryBuilder subAggQuery = QueryBuilders.boolQuery()//
			.must(QueryBuilders.termQuery(mainRole + ".show", true))//
			.mustNot(QueryBuilders.existsQuery(mainRole + ".readAt"));

	TermsBuilder aggBuilder = AggregationBuilders.terms("notifications")//
			.field(COMPANY_ID).include(companyIds)//
			.subAggregation(AggregationBuilders.filter("notread")//
					.filter(subAggQuery));

	Terms agg = (Terms) elastic.prepareSearch()//
			.setIndices(alias).setTypes(NOTIFICATION_TYPE)//
			.setQuery(query)//
			.addAggregation(aggBuilder)//
			.setSize(0)//
			.get()//
			.getAggregations()//
			.get("notifications");

	for (Company company : companies) {
		Bucket bucket = agg.getBucketByKey(company.id);
		if (bucket != null) {
			Filter agg2 = (Filter) bucket.getAggregations().get("notread");
			company.notifications = agg2 == null ? 0 : agg2.getDocCount();
		}
	}
}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:37,代码来源:TooleeResource.java

示例12: buildAggregation

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
private AbstractAggregationBuilder buildAggregation(StatsTrendRequest request) {
    DateHistogram.Interval interval = Utils.getHistogramInterval(request.getPeriod());
    AbstractAggregationBuilder dateHistogramBuilder = Utils.buildDateHistogramAggregation(request.getTimestamp(), interval)
            .subAggregation(Utils.buildExtendedStatsAggregation(request.getField()))
            .subAggregation(Utils.buildPercentileAggregation(request.getField()));

    if (CollectionUtils.isNullOrEmpty(getParameter().getNesting())) {
        return dateHistogramBuilder;
    }

    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;
        }
    }
    termsBuilder.subAggregation(dateHistogramBuilder);
    return rootBuilder;
}
 
开发者ID:Flipkart,项目名称:foxtrot,代码行数:29,代码来源:StatsTrendAction.java

示例13: convert

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
@Override
public AggregationBuilder convert(QueryConverter queryConverter, Aggregation aggregation) {

    TermsBuilder result = terms(getName(aggregation));

    addField(aggregation, result);
    addScript(aggregation, result);

    Integer limit = aggregation.getInteger("limit");
    if (limit != null) {
        result.size(limit);
    }

    // todo - add ordering
    Terms.Order order = Terms.Order.count(false);
    Sort sort = Coerce.to(aggregation.get("order"), Sort.class, null);
    if (sort != null) {
        boolean asc = Sort.Direction.Ascending.equals(sort.getDirection());
        if (Sort.Type.Count.equals(sort.getType())) {
            order = Terms.Order.count(asc);
        } else if (Sort.Type.Lexical.equals(sort.getType())) {
            order = Terms.Order.term(asc);
        }
    }
    result.order(order);

    addSubAggs(queryConverter, aggregation, result);
    return result;
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:30,代码来源:TermAggregationConverter.java

示例14: getFacetBuilder

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
public static AggregationBuilder getFacetBuilder(MultiValueFacet multiValueFacet) {
    FacetConfiguration facetConfiguration = multiValueFacet.getFacetConfiguration();
    JSONObject facetData = facetConfiguration.getData();

    if (multiValueFacet.isStatic()) {
        return null;
    }
    TermsBuilder termsFacetBuilder = AggregationBuilders.terms(facetConfiguration.getFieldName());
    if (facetData.has("maxTerms")) {
        termsFacetBuilder.size(facetData.getInt("maxTerms"));
    }
    termsFacetBuilder.field(facetConfiguration.getFieldName());
    return termsFacetBuilder;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:15,代码来源:LiferayFacetParser.java

示例15: buildFacets

import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; //导入依赖的package包/类
@Override
public List<AggregationBuilder> buildFacets() {
    TermsBuilder termsBuilder = AggregationBuilders.terms(getEsFieldName()).field(getEsFieldName()).size(size);
    MissingBuilder missingBuilder = AggregationBuilders.missing("missing_" + getEsFieldName()).field(getEsFieldName());
    // Elastic search has a bug with excludes so don't use it. https://github.com/elastic/elasticsearch/issues/18575
    // if (exclude != null) {
    // termsBuilder.exclude(exclude);
    // }
    return Lists.newArrayList(termsBuilder, missingBuilder);
}
 
开发者ID:alien4cloud,项目名称:elasticsearch-mapping-parent,代码行数:11,代码来源:TermsAggregationBuilderHelper.java


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