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


Java Bucket类代码示例

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


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

示例1: writeOrder

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public static void writeOrder(Terms.Order order, StreamOutput out) throws IOException {
    if (order instanceof Aggregation) {
        out.writeByte(order.id());
        Aggregation aggregationOrder = (Aggregation) order;
        out.writeBoolean(((MultiBucketsAggregation.Bucket.SubAggregationComparator) aggregationOrder.comparator).asc());
        AggregationPath path = ((Aggregation) order).path();
        out.writeString(path.toString());
    } else if (order instanceof CompoundOrder) {
        CompoundOrder compoundOrder = (CompoundOrder) order;
            out.writeByte(order.id());
            out.writeVInt(compoundOrder.orderElements.size());
            for (Terms.Order innerOrder : compoundOrder.orderElements) {
                Streams.writeOrder(innerOrder, out);
            }
    } else {
        out.writeByte(order.id());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:InternalOrder.java

示例2: assertNoDocCountError

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
private void assertNoDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));

    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), equalTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), equalTo(0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TermsDocCountErrorIT.java

示例3: assertUnboundedDocCountError

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
private void assertUnboundedDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));

    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(),anyOf(equalTo(-1L), equalTo(0L)));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), anyOf(equalTo(-1L), equalTo(0L)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TermsDocCountErrorIT.java

示例4: testSimpleDiversity

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public void testSimpleDiversity() throws Exception {
    int MAX_DOCS_PER_AUTHOR = 1;
    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100);
    sampleAgg.field("author").maxDocsPerValue(MAX_DOCS_PER_AUTHOR).executionHint(randomExecutionHint());
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy"))
            .setFrom(0).setSize(60)
            .addAggregation(sampleAgg)
            .execute()
            .actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    Terms authors = sample.getAggregations().get("authors");
    Collection<Bucket> testBuckets = authors.getBuckets();

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket.getDocCount(), lessThanOrEqualTo((long) NUM_SHARDS * MAX_DOCS_PER_AUTHOR));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DiversifiedSamplerIT.java

示例5: testNestedDiversity

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public void testNestedDiversity() throws Exception {
    // Test multiple samples gathered under buckets made by a parent agg
    int MAX_DOCS_PER_AUTHOR = 1;
    TermsAggregationBuilder rootTerms = terms("genres").field("genre");

    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100);
    sampleAgg.field("author").maxDocsPerValue(MAX_DOCS_PER_AUTHOR).executionHint(randomExecutionHint());
    sampleAgg.subAggregation(terms("authors").field("author"));

    rootTerms.subAggregation(sampleAgg);
    SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH)
            .addAggregation(rootTerms).execute().actionGet();
    assertSearchResponse(response);
    Terms genres = response.getAggregations().get("genres");
    Collection<Bucket> genreBuckets = genres.getBuckets();
    for (Terms.Bucket genreBucket : genreBuckets) {
        Sampler sample = genreBucket.getAggregations().get("sample");
        Terms authors = sample.getAggregations().get("authors");
        Collection<Bucket> testBuckets = authors.getBuckets();

        for (Terms.Bucket testBucket : testBuckets) {
            assertThat(testBucket.getDocCount(), lessThanOrEqualTo((long) NUM_SHARDS * MAX_DOCS_PER_AUTHOR));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:DiversifiedSamplerIT.java

示例6: testSimpleSampler

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public void testSimpleSampler() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH)
            .setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    Terms authors = sample.getAggregations().get("authors");
    Collection<Bucket> testBuckets = authors.getBuckets();

    long maxBooksPerAuthor = 0;
    for (Terms.Bucket testBucket : testBuckets) {
        maxBooksPerAuthor = Math.max(testBucket.getDocCount(), maxBooksPerAuthor);
    }
    assertThat(maxBooksPerAuthor, equalTo(3L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SamplerIT.java

示例7: getGroupResults

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
private List<GroupResult> getGroupResults(GroupRequest groupRequest, int index, Aggregations aggregations, Map<String, FieldType> commonColumnMetadata) {
  List<Group> groups = groupRequest.getGroups();
  String field = groups.get(index).getField();
  Terms terms = aggregations.get(getGroupByAggregationName(field));
  List<GroupResult> searchResultGroups = new ArrayList<>();
  for(Bucket bucket: terms.getBuckets()) {
    GroupResult groupResult = new GroupResult();
    groupResult.setKey(formatKey(bucket.getKey(), commonColumnMetadata.get(field)));
    groupResult.setTotal(bucket.getDocCount());
    Optional<String> scoreField = groupRequest.getScoreField();
    if (scoreField.isPresent()) {
      Sum score = bucket.getAggregations().get(getSumAggregationName(scoreField.get()));
      groupResult.setScore(score.getValue());
    }
    if (index < groups.size() - 1) {
      groupResult.setGroupedBy(groups.get(index + 1).getField());
      groupResult.setGroupResults(getGroupResults(groupRequest, index + 1, bucket.getAggregations(), commonColumnMetadata));
    }
    searchResultGroups.add(groupResult);
  }
  return searchResultGroups;
}
 
开发者ID:apache,项目名称:metron,代码行数:23,代码来源:ElasticsearchDao.java

示例8: compare

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
@Override
public int compare(Bucket o1, Bucket o2) {
    int result = 0;
    for (Iterator<Terms.Order> itr = compoundOrder.iterator(); itr.hasNext() && result == 0;) {
        result = itr.next().comparator(aggregator).compare(o1, o2);
    }
    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:InternalOrder.java

示例9: assertNoDocCountErrorSingleResponse

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
private void assertNoDocCountErrorSingleResponse(int size, SearchResponse testResponse) {
    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), equalTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        assertThat(testBucket.getDocCountError(), equalTo(0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TermsDocCountErrorIT.java

示例10: testIssue10719

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public void testIssue10719() throws Exception {
    // Tests that we can refer to nested elements under a sample in a path
    // statement
    boolean asc = randomBoolean();
    SearchResponse response = client().prepareSearch("test").setTypes("book").setSearchType(SearchType.QUERY_THEN_FETCH)
            .addAggregation(terms("genres")
                    .field("genre")
                    .order(Terms.Order.aggregation("sample>max_price.value", asc))
                    .subAggregation(sampler("sample").shardSize(100)
                            .subAggregation(max("max_price").field("price")))
            ).execute().actionGet();
    assertSearchResponse(response);
    Terms genres = response.getAggregations().get("genres");
    Collection<Bucket> genreBuckets = genres.getBuckets();
    // For this test to be useful we need >1 genre bucket to compare
    assertThat(genreBuckets.size(), greaterThan(1));
    double lastMaxPrice = asc ? Double.MIN_VALUE : Double.MAX_VALUE;
    for (Terms.Bucket genreBucket : genres.getBuckets()) {
        Sampler sample = genreBucket.getAggregations().get("sample");
        Max maxPriceInGenre = sample.getAggregations().get("max_price");
        double price = maxPriceInGenre.getValue();
        if (asc) {
            assertThat(price, greaterThanOrEqualTo(lastMaxPrice));
        } else {
            assertThat(price, lessThanOrEqualTo(lastMaxPrice));
        }
        lastMaxPrice = price;
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:DiversifiedSamplerIT.java

示例11: countWordByDomain

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
/**
 * 统计网站中的词频
 * @param domain
 * @return Map<词,词频>
 */
public Map<String, Long> countWordByDomain(String domain) {
	SearchResponse response = search().setQuery(QueryBuilders.matchQuery("domain", domain))
			.addAggregation(AggregationBuilders.terms("content").field("content").size(200)).get();
	List<Bucket> list = (List<Bucket>)((Terms)response.getAggregations().get("content")).getBuckets();
	Map<String, Long> count = new LinkedHashMap<>();
	list.stream().filter(bucket -> bucket.getKeyAsString().length() > 1).forEach(bucket -> {
		count.put(bucket.getKeyAsString(), bucket.getDocCount());
	});
	return count;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:16,代码来源:WebpageDAO.java

示例12: countDomainByGatherTime

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
/**
 * 统计指定网站每天抓取数量
 * @param domain
 * @return
 */
public Map<Date, Long> countDomainByGatherTime(String domain) {
	SearchResponse response = search().setQuery(QueryBuilders.matchQuery("domain", domain))
			.addAggregation(AggregationBuilders.dateHistogram("agg").field("gatherTime")
					.dateHistogramInterval(DateHistogramInterval.DAY).order(Histogram.Order.KEY_DESC)).get();
	Map<Date, Long> count = new LinkedHashMap<>();
	for(Histogram.Bucket bucket:((Histogram)(Histogram)response.getAggregations().get("agg")).getBuckets()) 
		count.put(((DateTime)bucket.getKey()).toDate(), bucket.getDocCount());
	return count;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:15,代码来源:WebpageDAO.java

示例13: relatedInfo

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public Pair<Map<String, List<Bucket>>, List<Webpage>> relatedInfo(String query, int size) {
	SearchResponse response = search().setQuery(QueryBuilders.queryStringQuery(query))
			.addAggregation(AggregationBuilders.terms("People").field("namedEntity.nr"))
			.addAggregation(AggregationBuilders.terms("Location").field("namedEntity.ns"))
			.addAggregation(AggregationBuilders.terms("Institution").field("namedEntity.nt"))
			.addAggregation(AggregationBuilders.terms("Keyword").field("keyword"))
			.setSize(size).get();
	Map<String, List<Bucket>> map = new HashMap<>();
	map.put("People", response.getAggregations().get("People"));
	map.put("Location", response.getAggregations().get("Location"));
	map.put("Institution", response.getAggregations().get("Institution"));
	map.put("Keyword", response.getAggregations().get("Keyword"));
	return Pair.of(map, hitsToList(response.getHits()));
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:15,代码来源:WebpageDAO.java

示例14: SearchResult

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
public SearchResult(SearchResponse resp, Select select) throws SqlParseException {
	Aggregations aggs = resp.getAggregations();
	if (aggs.get("filter") != null) {
		InternalFilter inf = aggs.get("filter");
		aggs = inf.getAggregations();
	}
	if (aggs.get("group by") != null) {
		InternalTerms terms = aggs.get("group by");
		Collection<Bucket> buckets = terms.getBuckets();
		this.total = buckets.size();
		results = new ArrayList<>(buckets.size());
		for (Bucket bucket : buckets) {
			Map<String, Object> aggsMap = toAggsMap(bucket.getAggregations().getAsMap());
			aggsMap.put("docCount", bucket.getDocCount());
			results.add(aggsMap);
		}
	} else {
		results = new ArrayList<>(1);
		this.total = 1;
		Map<String, Object> map = new HashMap<>();
		for (Aggregation aggregation : aggs) {
			map.put(aggregation.getName(), covenValue(aggregation));
		}
		results.add(map);
	}

}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:28,代码来源:SearchResult.java

示例15: getAggregatedEntities

import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; //导入依赖的package包/类
/**
 * Method recursively goes through aggregations, creates entities and adds
 * fields to them. When entity has all fields from aggregations it adds to
 * entities list. If groupBy has aggregation $count then property with
 * {@link #countAlias} name will be added to entity with doc count from
 * response aggregations.
 *
 * @param aggs
 *            response aggregations
 * @param parent
 *            parent entity
 * @param entityType
 *            entity type
 * @return list of entities
 */
protected List<Entity> getAggregatedEntities(Map<String, Aggregation> aggs, Entity parent,
        ElasticEdmEntityType entityType) {
    List<Entity> entities = new ArrayList<>();
    for (Entry<String, Terms> entry : collectTerms(aggs).entrySet()) {
        for (Bucket bucket : entry.getValue().getBuckets()) {
            Entity entity = new Entity();
            if (parent != null) {
                entity.getProperties().addAll(parent.getProperties());
            }
            Property property = createProperty(entry.getKey(), bucket.getKey(), entityType);
            entity.addProperty(property);
            Map<String, Aggregation> subAggs = bucket.getAggregations().asMap();
            if (subAggs.isEmpty()) {
                addAggsAndCountIfNeeded(aggs, bucket.getDocCount(), entity, entityType);
                entities.add(entity);
            } else {
                List<Entity> subEntities = getAggregatedEntities(subAggs, entity, entityType);
                if (subEntities.isEmpty()) {
                    addAggsAndCountIfNeeded(subAggs, bucket.getDocCount(), entity, entityType);
                    entities.add(entity);
                } else {
                    entities.addAll(subEntities);
                }
            }
        }
    }
    return entities;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:44,代码来源:BucketsAggregationsParser.java


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