Search in sources :

Example 6 with Percentile

use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.

the class TDigestPercentilesIT method assertConsistent.

private void assertConsistent(double[] pcts, Percentiles percentiles, long minValue, long maxValue) {
    final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(percentiles);
    assertEquals(pcts.length, percentileList.size());
    for (int i = 0; i < pcts.length; ++i) {
        final Percentile percentile = percentileList.get(i);
        assertThat(percentile.getPercent(), equalTo(pcts[i]));
        double value = percentile.getValue();
        assertThat(value, greaterThanOrEqualTo((double) minValue));
        assertThat(value, lessThanOrEqualTo((double) maxValue));
        if (percentile.getPercent() == 0) {
            assertThat(value, equalTo((double) minValue));
        }
        if (percentile.getPercent() == 100) {
            assertThat(value, equalTo((double) maxValue));
        }
    }
    for (int i = 1; i < percentileList.size(); ++i) {
        assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
    }
}
Also used : Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)

Example 7 with Percentile

use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.

the class HDRPercentilesIT method assertConsistent.

private void assertConsistent(double[] pcts, Percentiles percentiles, long minValue, long maxValue, int numberSigDigits) {
    final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(percentiles);
    assertEquals(pcts.length, percentileList.size());
    for (int i = 0; i < pcts.length; ++i) {
        final Percentile percentile = percentileList.get(i);
        assertThat(percentile.getPercent(), equalTo(pcts[i]));
        double value = percentile.getValue();
        double allowedError = value / Math.pow(10, numberSigDigits);
        assertThat(value, greaterThanOrEqualTo(minValue - allowedError));
        assertThat(value, lessThanOrEqualTo(maxValue + allowedError));
        if (percentile.getPercent() == 0) {
            assertThat(value, closeTo(minValue, allowedError));
        }
        if (percentile.getPercent() == 100) {
            assertThat(value, closeTo(maxValue, allowedError));
        }
    }
    for (int i = 1; i < percentileList.size(); ++i) {
        assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
    }
}
Also used : Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)

Example 8 with Percentile

use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.

the class HDRPercentileRanksIT method assertConsistent.

private void assertConsistent(double[] pcts, PercentileRanks values, long minValue, long maxValue, int numberSigDigits) {
    final List<Percentile> percentileList = 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) {
            double allowedError = minValue / Math.pow(10, numberSigDigits);
            assertThat(percentile.getValue(), lessThanOrEqualTo(minValue + allowedError));
        }
        if (percentile.getPercent() == 100) {
            double allowedError = maxValue / Math.pow(10, numberSigDigits);
            assertThat(percentile.getValue(), greaterThanOrEqualTo(maxValue - allowedError));
        }
    }
    for (int i = 1; i < percentileList.size(); ++i) {
        assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
    }
}
Also used : Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)

Example 9 with Percentile

use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.

the class PercentilesBucketIT method assertPercentileBucket.

private void assertPercentileBucket(double[] values, PercentilesBucket percentiles) {
    for (Percentile percentile : percentiles) {
        assertEquals(percentiles.percentile(percentile.getPercent()), percentile.getValue(), 0d);
        int index = (int) Math.round((percentile.getPercent() / 100.0) * (values.length - 1));
        assertThat(percentile.getValue(), equalTo(values[index]));
    }
}
Also used : Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)

Aggregations

Percentile (org.elasticsearch.search.aggregations.metrics.percentiles.Percentile)9 IndexReader (org.apache.lucene.index.IndexReader)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)4 PercentileRanks (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks)4 PercentileRanksAggregationBuilder (org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder)4 Document (org.apache.lucene.document.Document)2 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)2 MultiReader (org.apache.lucene.index.MultiReader)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 Directory (org.apache.lucene.store.Directory)2