org.elasticsearch.search.aggregations.metrics.Percentile Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.metrics.Percentile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchFeatureDaoTests.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Object[] getFeaturesForPeriodThrowIllegalStateData() {
    String aggName = "aggName";

    InternalTDigestPercentiles empty = mock(InternalTDigestPercentiles.class);
    Iterator<Percentile> emptyIterator = mock(Iterator.class);
    when(empty.iterator()).thenReturn(emptyIterator);
    when(emptyIterator.hasNext()).thenReturn(false);
    when(empty.getName()).thenReturn(aggName);

    MultiBucketsAggregation multiBucket = mock(MultiBucketsAggregation.class);
    when(multiBucket.getName()).thenReturn(aggName);

    return new Object[] {
        new Object[] { asList(empty), asList(aggName), null },
        new Object[] { asList(multiBucket), asList(aggName), null }, };
}
 
Example #2
Source File: SearchFeatureDao.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
private double parseAggregation(Aggregation aggregation) {
    Double result = null;
    if (aggregation instanceof SingleValue) {
        result = ((SingleValue) aggregation).value();
    } else if (aggregation instanceof InternalTDigestPercentiles) {
        Iterator<Percentile> percentile = ((InternalTDigestPercentiles) aggregation).iterator();
        if (percentile.hasNext()) {
            result = percentile.next().getValue();
        }
    }
    return Optional.ofNullable(result).orElseThrow(() -> new IllegalStateException("Failed to parse aggregation " + aggregation));
}
 
Example #3
Source File: SearchFeatureDaoTests.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Object[] getFeaturesForPeriodData() {
    String maxName = "max";
    double maxValue = 2;
    Max max = mock(Max.class);
    when(max.value()).thenReturn(maxValue);
    when(max.getName()).thenReturn(maxName);

    String percentileName = "percentile";
    double percentileValue = 1;
    InternalTDigestPercentiles percentiles = mock(InternalTDigestPercentiles.class);
    Iterator<Percentile> percentilesIterator = mock(Iterator.class);
    Percentile percentile = mock(Percentile.class);
    when(percentiles.iterator()).thenReturn(percentilesIterator);
    when(percentilesIterator.hasNext()).thenReturn(true);
    when(percentilesIterator.next()).thenReturn(percentile);
    when(percentile.getValue()).thenReturn(percentileValue);
    when(percentiles.getName()).thenReturn(percentileName);

    String missingName = "missing";
    Max missing = mock(Max.class);
    when(missing.value()).thenReturn(Double.NaN);
    when(missing.getName()).thenReturn(missingName);

    String infinityName = "infinity";
    Max infinity = mock(Max.class);
    when(infinity.value()).thenReturn(Double.POSITIVE_INFINITY);
    when(infinity.getName()).thenReturn(infinityName);

    String emptyName = "empty";
    InternalTDigestPercentiles empty = mock(InternalTDigestPercentiles.class);
    Iterator<Percentile> emptyIterator = mock(Iterator.class);
    when(empty.iterator()).thenReturn(emptyIterator);
    when(emptyIterator.hasNext()).thenReturn(false);
    when(empty.getName()).thenReturn(emptyName);

    return new Object[] {
        new Object[] { asList(max), asList(maxName), new double[] { maxValue }, },
        new Object[] { asList(percentiles), asList(percentileName), new double[] { percentileValue } },
        new Object[] { asList(missing), asList(missingName), null },
        new Object[] { asList(infinity), asList(infinityName), null },
        new Object[] { asList(max, percentiles), asList(maxName, percentileName), new double[] { maxValue, percentileValue } },
        new Object[] { asList(max, percentiles), asList(percentileName, maxName), new double[] { percentileValue, maxValue } },
        new Object[] { asList(max, percentiles, missing), asList(maxName, percentileName, missingName), null }, };
}