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


Java MinAggregationBuilder类代码示例

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


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

示例1: getMinId

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
protected final int getMinId(String indexName, String columnName) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName);
    searchRequestBuilder.setTypes("type");
    searchRequestBuilder.setSize(0);
    MinAggregationBuilder aggregation = AggregationBuilders.min("agg").field(columnName);
    searchRequestBuilder.addAggregation(aggregation);

    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    Min agg = searchResponse.getAggregations().get("agg");

    int id = (int)agg.getValue();
    if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) {
        return 0;
    } else {
        return id;
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:19,代码来源:EsDAO.java

示例2: testCase

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
private void testCase(Query query, IndexSearcher indexSearcher, Consumer<InternalChildren> verify)
        throws IOException {

    ChildrenAggregationBuilder aggregationBuilder = new ChildrenAggregationBuilder("_name", CHILD_TYPE);
    aggregationBuilder.subAggregation(new MinAggregationBuilder("in_child").field("number"));

    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    fieldType.setName("number");
    InternalChildren result = search(indexSearcher, query, aggregationBuilder, fieldType);
    verify.accept(result);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:ParentToChildrenAggregatorTests.java

示例3: testSampler

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
/**
 * Uses the sampler aggregation to find the minimum value of a field out of the top 3 scoring documents in a search.
 */
public void testSampler() throws IOException {
    TextFieldType textFieldType = new TextFieldType();
    textFieldType.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.GLOBAL, new StandardAnalyzer()));
    MappedFieldType numericFieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    numericFieldType.setName("int");

    IndexWriterConfig indexWriterConfig = newIndexWriterConfig();
    indexWriterConfig.setMaxBufferedDocs(100);
    indexWriterConfig.setRAMBufferSizeMB(100); // flush on open to have a single segment with predictable docIds
    try (Directory dir = newDirectory();
            IndexWriter w = new IndexWriter(dir, indexWriterConfig)) {
        for (long value : new long[] {7, 3, -10, -6, 5, 50}) {
            Document doc = new Document();
            StringBuilder text = new StringBuilder();
            for (int i = 0; i < value; i++) {
                text.append("good ");
            }
            doc.add(new Field("text", text.toString(), textFieldType));
            doc.add(new SortedNumericDocValuesField("int", value));
            w.addDocument(doc);
        }

        SamplerAggregationBuilder aggBuilder = new SamplerAggregationBuilder("sampler")
                .shardSize(3)
                .subAggregation(new MinAggregationBuilder("min")
                        .field("int"));
        try (IndexReader reader = DirectoryReader.open(w)) {
            assertEquals("test expects a single segment", 1, reader.leaves().size());
            IndexSearcher searcher = new IndexSearcher(reader);
            Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType,
                    numericFieldType);
            Min min = sampler.getAggregations().get("min");
            assertEquals(5.0, min.getValue(), 0);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:SamplerAggregatorTests.java

示例4: testCase

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
private void testCase(CheckedConsumer<RandomIndexWriter, IOException> buildIndex, BiConsumer<InternalGlobal, InternalMin> verify)
        throws IOException {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    buildIndex.accept(indexWriter);
    indexWriter.close();

    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

    GlobalAggregationBuilder aggregationBuilder = new GlobalAggregationBuilder("_name");
    aggregationBuilder.subAggregation(new MinAggregationBuilder("in_global").field("number"));
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    fieldType.setName("number");
    try (GlobalAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType)) {
        try {
            aggregator.preCollection();
            indexSearcher.search(new MatchAllDocsQuery(), aggregator);
            aggregator.postCollection();
            InternalGlobal result = (InternalGlobal) aggregator.buildAggregation(0L);
            verify.accept(result, (InternalMin) result.getAggregations().asMap().get("in_global"));
        } finally {
            IOUtils.close(aggregator.subAggregators());
        }
    }
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:GlobalAggregatorTests.java

示例5: min

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
/**
 * Create a new {@link Min} aggregation with the given name.
 */
public static MinAggregationBuilder min(String name) {
    return new MinAggregationBuilder(name);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:AggregationBuilders.java

示例6: doCreateTestAggregatorFactory

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的package包/类
@Override
protected MinAggregationBuilder doCreateTestAggregatorFactory() {
    return new MinAggregationBuilder("foo");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:MinTests.java

示例7: populateBuffer

import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; //导入依赖的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);
}
 
开发者ID:DigitalPebble,项目名称:storm-crawler,代码行数:72,代码来源:AggregationSpout.java


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