當前位置: 首頁>>代碼示例>>Java>>正文


Java PercentileRanks類代碼示例

本文整理匯總了Java中org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks的典型用法代碼示例。如果您正苦於以下問題:Java PercentileRanks類的具體用法?Java PercentileRanks怎麽用?Java PercentileRanks使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PercentileRanks類屬於org.elasticsearch.search.aggregations.metrics.percentiles包,在下文中一共展示了PercentileRanks類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUnmapped

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
@Override
public void testUnmapped() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client()
            .prepareSearch("idx_unmapped")
            .setQuery(matchAllQuery())
            .addAggregation(
                    percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits)
                    .field("value").values(0, 10, 15, 100))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));

    PercentileRanks reversePercentiles = searchResponse.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(0), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(100), equalTo(Double.NaN));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:HDRPercentileRanksIT.java

示例2: assertConsistent

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
private void assertConsistent(double[] pcts, PercentileRanks values, long minValue, long maxValue) {
    final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(values);
    assertEquals(pcts.length, percentileList.size());
    for (int i = 0; i < pcts.length; ++i) {
        final Percentile percentile = percentileList.get(i);
        assertThat(percentile.getValue(), equalTo(pcts[i]));
        assertThat(percentile.getPercent(), greaterThanOrEqualTo(0.0));
        assertThat(percentile.getPercent(), lessThanOrEqualTo(100.0));

        if (percentile.getPercent() == 0) {
            assertThat(percentile.getValue(), lessThanOrEqualTo((double) minValue));
        }
        if (percentile.getPercent() == 100) {
            assertThat(percentile.getValue(), greaterThanOrEqualTo((double) maxValue));
        }
    }

    for (int i = 1; i < percentileList.size(); ++i) {
        assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:TDigestPercentileRanksIT.java

示例3: testEmptyAggregation

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
@Override
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
                    .subAggregation(randomCompression(percentileRanks("percentile_ranks").field("value"))
                            .values(10, 15)))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    Histogram.Bucket bucket = histo.getBuckets().get(1);
    assertThat(bucket, notNullValue());

    PercentileRanks reversePercentiles = bucket.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:TDigestPercentileRanksIT.java

示例4: testUnmapped

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
@Override
public void testUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
            .setQuery(matchAllQuery())
            .addAggregation(randomCompression(percentileRanks("percentile_ranks"))
                    .field("value")
                    .values(0, 10, 15, 100))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));

    PercentileRanks reversePercentiles = searchResponse.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(0), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(100), equalTo(Double.NaN));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:TDigestPercentileRanksIT.java

示例5: testEmptyAggregation

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
@Override
public void testEmptyAggregation() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client()
            .prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                    histogram("histo")
                            .field("value")
                            .interval(1L)
                            .minDocCount(0)
                            .subAggregation(
                                    percentileRanks("percentile_ranks").field("value").method(PercentilesMethod.HDR)
                                    .numberOfSignificantValueDigits(sigDigits).values(10, 15)))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    Histogram.Bucket bucket = histo.getBuckets().get(1);
    assertThat(bucket, notNullValue());

    PercentileRanks reversePercentiles = bucket.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:29,代碼來源:HDRPercentileRanksIT.java

示例6: testEmpty

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
public void testEmpty() throws IOException {
    PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg")
            .field("field")
            .method(PercentilesMethod.HDR)
            .values(0.5);
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
    fieldType.setName("field");
    try (IndexReader reader = new MultiReader()) {
        IndexSearcher searcher = new IndexSearcher(reader);
        PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
        Percentile rank = ranks.iterator().next();
        assertEquals(Double.NaN, rank.getPercent(), 0d);
        assertEquals(0.5, rank.getValue(), 0d);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:HDRPercentileRanksAggregatorTests.java

示例7: testSimple

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
public void testSimple() throws IOException {
    try (Directory dir = newDirectory();
            RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
        for (double value : new double[] {3, 0.2, 10}) {
            Document doc = new Document();
            doc.add(new SortedNumericDocValuesField("field", NumericUtils.doubleToSortableLong(value)));
            w.addDocument(doc);
        }

        PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg")
                .field("field")
                .method(PercentilesMethod.HDR)
                .values(0.1, 0.5, 12);
        MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
        fieldType.setName("field");
        try (IndexReader reader = w.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
            Iterator<Percentile> rankIterator = ranks.iterator();
            Percentile rank = rankIterator.next();
            assertEquals(0.1, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.equalTo(0d));
            rank = rankIterator.next();
            assertEquals(0.5, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.greaterThan(0d));
            assertThat(rank.getPercent(), Matchers.lessThan(100d));
            rank = rankIterator.next();
            assertEquals(12, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.equalTo(100d));
            assertFalse(rankIterator.hasNext());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:34,代碼來源:HDRPercentileRanksAggregatorTests.java

示例8: testEmpty

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
public void testEmpty() throws IOException {
    PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg")
            .field("field")
            .method(PercentilesMethod.TDIGEST)
            .values(0.5);
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
    fieldType.setName("field");
    try (IndexReader reader = new MultiReader()) {
        IndexSearcher searcher = new IndexSearcher(reader);
        PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
        Percentile rank = ranks.iterator().next();
        assertEquals(Double.NaN, rank.getPercent(), 0d);
        assertEquals(0.5, rank.getValue(), 0d);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:TDigestPercentileRanksAggregatorTests.java

示例9: testSimple

import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks; //導入依賴的package包/類
public void testSimple() throws IOException {
    try (Directory dir = newDirectory();
            RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
        for (double value : new double[] {3, 0.2, 10}) {
            Document doc = new Document();
            doc.add(new SortedNumericDocValuesField("field", NumericUtils.doubleToSortableLong(value)));
            w.addDocument(doc);
        }

        PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg")
                .field("field")
                .method(PercentilesMethod.TDIGEST)
                .values(0.1, 0.5, 12);
        MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
        fieldType.setName("field");
        try (IndexReader reader = w.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
            Iterator<Percentile> rankIterator = ranks.iterator();
            Percentile rank = rankIterator.next();
            assertEquals(0.1, rank.getValue(), 0d);
            // TODO: Fix T-Digest: this assertion should pass but we currently get ~15
            // https://github.com/elastic/elasticsearch/issues/14851
            // assertThat(rank.getPercent(), Matchers.equalTo(0d));
            rank = rankIterator.next();
            assertEquals(0.5, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.greaterThan(0d));
            assertThat(rank.getPercent(), Matchers.lessThan(100d));
            rank = rankIterator.next();
            assertEquals(12, rank.getValue(), 0d);
            // TODO: Fix T-Digest: this assertion should pass but we currently get ~59
            // https://github.com/elastic/elasticsearch/issues/14851
            // assertThat(rank.getPercent(), Matchers.equalTo(100d));
            assertFalse(rankIterator.hasNext());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:38,代碼來源:TDigestPercentileRanksAggregatorTests.java


注:本文中的org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。