本文整理汇总了Java中org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats类的典型用法代码示例。如果您正苦于以下问题:Java ExtendedStats类的具体用法?Java ExtendedStats怎么用?Java ExtendedStats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtendedStats类属于org.elasticsearch.search.aggregations.metrics.stats.extended包,在下文中一共展示了ExtendedStats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reduceStatisticsResults
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
private static StatisticsResult reduceStatisticsResults(List<Aggregation> aggs) {
List<StatisticsResult> results = new ArrayList<>();
for (Aggregation agg : aggs) {
if (agg instanceof ExtendedStats) {
ExtendedStats extendedStats = (ExtendedStats) agg;
long count = extendedStats.getCount();
double sum = extendedStats.getSum();
double min = extendedStats.getMin();
double max = extendedStats.getMax();
double standardDeviation = extendedStats.getStdDeviation();
results.add(new StatisticsResult(count, sum, min, max, standardDeviation));
} else {
throw new MemgraphException("Aggregation is not a statistics: " + agg.getClass().getName());
}
}
return StatisticsResult.combine(results);
}
示例2: testUnmapped
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Override
public void testUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
.setQuery(matchAllQuery())
.addAggregation(extendedStats("stats").field("value"))
.execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
ExtendedStats stats = searchResponse.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getAvg(), equalTo(Double.NaN));
assertThat(stats.getMin(), equalTo(Double.POSITIVE_INFINITY));
assertThat(stats.getMax(), equalTo(Double.NEGATIVE_INFINITY));
assertThat(stats.getSum(), equalTo(0.0));
assertThat(stats.getCount(), equalTo(0L));
assertThat(stats.getSumOfSquares(), equalTo(0.0));
assertThat(stats.getVariance(), equalTo(Double.NaN));
assertThat(stats.getStdDeviation(), equalTo(Double.NaN));
assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER)), is(true));
assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER)), is(true));
}
示例3: testPartiallyUnmapped
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
public void testPartiallyUnmapped() {
double sigma = randomDouble() * 5;
ExtendedStats s1 = client().prepareSearch("idx")
.addAggregation(extendedStats("stats").field("value").sigma(sigma)).get()
.getAggregations().get("stats");
ExtendedStats s2 = client().prepareSearch("idx", "idx_unmapped")
.addAggregation(extendedStats("stats").field("value").sigma(sigma)).get()
.getAggregations().get("stats");
assertEquals(s1.getAvg(), s2.getAvg(), 1e-10);
assertEquals(s1.getCount(), s2.getCount());
assertEquals(s1.getMin(), s2.getMin(), 0d);
assertEquals(s1.getMax(), s2.getMax(), 0d);
assertEquals(s1.getStdDeviation(), s2.getStdDeviation(), 1e-10);
assertEquals(s1.getSumOfSquares(), s2.getSumOfSquares(), 1e-10);
assertEquals(s1.getStdDeviationBound(Bounds.LOWER), s2.getStdDeviationBound(Bounds.LOWER), 1e-10);
assertEquals(s1.getStdDeviationBound(Bounds.UPPER), s2.getStdDeviationBound(Bounds.UPPER), 1e-10);
}
示例4: testSingleValuedField
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Override
public void testSingleValuedField() throws Exception {
double sigma = randomDouble() * randomIntBetween(1, 10);
SearchResponse searchResponse = client().prepareSearch("idx")
.setQuery(matchAllQuery())
.addAggregation(extendedStats("stats").field("value").sigma(sigma))
.execute().actionGet();
assertHitCount(searchResponse, 10);
ExtendedStats stats = searchResponse.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getAvg(), equalTo((double) (1+2+3+4+5+6+7+8+9+10) / 10));
assertThat(stats.getMin(), equalTo(1.0));
assertThat(stats.getMax(), equalTo(10.0));
assertThat(stats.getSum(), equalTo((double) 1+2+3+4+5+6+7+8+9+10));
assertThat(stats.getCount(), equalTo(10L));
assertThat(stats.getSumOfSquares(), equalTo((double) 1+4+9+16+25+36+49+64+81+100));
assertThat(stats.getVariance(), equalTo(variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
checkUpperLowerBounds(stats, sigma);
}
示例5: testSingleValuedFieldDefaultSigma
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
public void testSingleValuedFieldDefaultSigma() throws Exception {
// Same as previous test, but uses a default value for sigma
SearchResponse searchResponse = client().prepareSearch("idx")
.setQuery(matchAllQuery())
.addAggregation(extendedStats("stats").field("value"))
.execute().actionGet();
assertHitCount(searchResponse, 10);
ExtendedStats stats = searchResponse.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getAvg(), equalTo((double) (1+2+3+4+5+6+7+8+9+10) / 10));
assertThat(stats.getMin(), equalTo(1.0));
assertThat(stats.getMax(), equalTo(10.0));
assertThat(stats.getSum(), equalTo((double) 1+2+3+4+5+6+7+8+9+10));
assertThat(stats.getCount(), equalTo(10L));
assertThat(stats.getSumOfSquares(), equalTo((double) 1+4+9+16+25+36+49+64+81+100));
assertThat(stats.getVariance(), equalTo(variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
checkUpperLowerBounds(stats, 2);
}
示例6: testSingleValuedFieldPartiallyUnmapped
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
double sigma = randomDouble() * randomIntBetween(1, 10);
SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped")
.setQuery(matchAllQuery())
.addAggregation(extendedStats("stats").field("value").sigma(sigma))
.execute().actionGet();
assertHitCount(searchResponse, 10);
ExtendedStats stats = searchResponse.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getAvg(), equalTo((double) (1+2+3+4+5+6+7+8+9+10) / 10));
assertThat(stats.getMin(), equalTo(1.0));
assertThat(stats.getMax(), equalTo(10.0));
assertThat(stats.getSum(), equalTo((double) 1+2+3+4+5+6+7+8+9+10));
assertThat(stats.getCount(), equalTo(10L));
assertThat(stats.getSumOfSquares(), equalTo((double) 1+4+9+16+25+36+49+64+81+100));
assertThat(stats.getVariance(), equalTo(variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
assertThat(stats.getStdDeviation(), equalTo(stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)));
checkUpperLowerBounds(stats, sigma);
}
示例7: testMultiValuedField
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Override
public void testMultiValuedField() throws Exception {
double sigma = randomDouble() * randomIntBetween(1, 10);
SearchResponse searchResponse = client().prepareSearch("idx")
.setQuery(matchAllQuery())
.addAggregation(extendedStats("stats").field("values").sigma(sigma))
.execute().actionGet();
assertHitCount(searchResponse, 10);
ExtendedStats stats = searchResponse.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getAvg(), equalTo((double) (2+3+4+5+6+7+8+9+10+11+3+4+5+6+7+8+9+10+11+12) / 20));
assertThat(stats.getMin(), equalTo(2.0));
assertThat(stats.getMax(), equalTo(12.0));
assertThat(stats.getSum(), equalTo((double) 2+3+4+5+6+7+8+9+10+11+3+4+5+6+7+8+9+10+11+12));
assertThat(stats.getCount(), equalTo(20L));
assertThat(stats.getSumOfSquares(), equalTo((double) 4+9+16+25+36+49+64+81+100+121+9+16+25+36+49+64+81+100+121+144));
assertThat(stats.getVariance(), equalTo(variance(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
assertThat(stats.getStdDeviation(), equalTo(stdDev(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)));
checkUpperLowerBounds(stats, sigma);
}
示例8: reduceStatisticsResults
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
private static StatisticsResult reduceStatisticsResults(List<Aggregation> aggs) {
List<StatisticsResult> results = new ArrayList<>();
for (Aggregation agg : aggs) {
if (agg instanceof ExtendedStats) {
ExtendedStats extendedStats = (ExtendedStats) agg;
long count = extendedStats.getCount();
double sum = extendedStats.getSum();
double min = extendedStats.getMin();
double max = extendedStats.getMax();
double standardDeviation = extendedStats.getStdDeviation();
results.add(new StatisticsResult(count, sum, min, max, standardDeviation));
} else {
throw new VertexiumException("Aggregation is not a statistics: " + agg.getClass().getName());
}
}
return StatisticsResult.combine(results);
}
示例9: parse
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Override
public FieldMetadata parse(FieldInfo info, ExtendedStats stats, int valuesPerDocument) {
long from = Math.round(stats.getMin());
long to = Math.round(stats.getMax());
String[] esPatterns = info.getJson().path(FORMAT_PROP).asText(MetadataConstants.DEFAULT_DATE_PATTERN).split(DATE_SEPARATOR);
String pattern = jodaToJDK(info, esPatterns);
Instant fromInstant = Instant.ofEpochMilli(from);
Instant toInstant = Instant.ofEpochMilli(to);
ChronoUnit unit = calculateTimeStep(fromInstant, toInstant, stats.getCount());
if(pattern != null) {
long increment = unit.between(fromInstant, toInstant) / stats.getCount();
return new DateFieldMetadata(info.getFullPath(), valuesPerDocument, fromInstant, toInstant, increment, unit, pattern);
} else {
return jodaToNumericUnit(info.getFullPath(), valuesPerDocument, fromInstant, toInstant, unit, esPatterns);
}
}
示例10: collectNumericData
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
private <T extends FieldMetadata> List<FieldMetadata> collectNumericData(Collection<FieldInfo> fields, ExtendedStatsAnalyzer<T> parser) {
if(fields.isEmpty()) {
return Collections.emptyList();
}
List<FieldMetadata> metadata = new ArrayList<>(fields.size());
SearchRequestBuilder builder = createNumericSearchBuilder(fields);
SearchResponse response = client.search(builder.request()).actionGet();
for(FieldInfo info : fields) {
InternalFilter filter = getAggregation(response, info, FILTER_AGG);
ExtendedStats stats = (ExtendedStats) filter.getAggregations().get(EXTENDED_STATS_AGG + info.getFullPath());
LOGGER.debug("Field {} total: {} MAX: {} MIN: {}", info.getFullPath(), stats.getCount(), stats.getMaxAsString(), stats.getMinAsString());
if(stats.getCount() <= ZERO_ITEMS) {
continue;
}
int valuesPerDocument = valuesPerDoc(response, filter, stats);
FieldMetadata meta = parser.parse(info, stats, valuesPerDocument);
LOGGER.debug("Registering metadata: {}", meta);
metadata.add(meta);
}
return metadata;
}
示例11: testSortingByMulValMetric
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
@Test
public void testSortingByMulValMetric() {
String termsColors = "colors", stats = "stats";
srb =
client.prepareSearch("cars").addAggregation(
AggregationBuilders.terms(termsColors).field("color")
.order(Order.aggregation("stats.variance", true))
.subAggregation(AggregationBuilders.extendedStats(stats).field("price")));
SearchResponse response = srb.execute().actionGet();
// read agg
Terms colorsTerms = (Terms) response.getAggregations().get("colors");
colorsTerms.getBuckets().forEach(
bucket -> {
double variancePrice =
((ExtendedStats) bucket.getAggregations().get(stats)).getVariance();
System.out.println(String.format("Key: %s, Doc count: %d, Variance: %f", bucket.getKey(),
bucket.getDocCount(), variancePrice));
});
}
开发者ID:destiny1020,项目名称:elasticsearch-java-client-examples,代码行数:22,代码来源:SortingMulValBucketsExamples.java
示例12: testRandomDoubles
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
public void testRandomDoubles() throws IOException {
MappedFieldType ft =
new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
ft.setName("field");
final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
testCase(ft,
iw -> {
int numDocs = randomIntBetween(10, 50);
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
int numValues = randomIntBetween(1, 5);
for (int j = 0; j < numValues; j++) {
double value = randomDoubleBetween(-100d, 100d, true);
long valueAsLong = NumericUtils.doubleToSortableLong(value);
doc.add(new SortedNumericDocValuesField("field", valueAsLong));
expected.add(value);
}
iw.addDocument(doc);
}
},
stats -> {
assertEquals(expected.count, stats.getCount(), 0);
assertEquals(expected.sum, stats.getSum(), TOLERANCE);
assertEquals(expected.min, stats.getMin(), 0);
assertEquals(expected.max, stats.getMax(), 0);
assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()),
stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()),
stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
}
);
}
示例13: testRandomLongs
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
public void testRandomLongs() throws IOException {
MappedFieldType ft =
new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
ft.setName("field");
final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
testCase(ft,
iw -> {
int numDocs = randomIntBetween(10, 50);
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
int numValues = randomIntBetween(1, 5);
for (int j = 0; j < numValues; j++) {
long value = randomIntBetween(-100, 100);
doc.add(new SortedNumericDocValuesField("field", value));
expected.add(value);
}
iw.addDocument(doc);
}
},
stats -> {
assertEquals(expected.count, stats.getCount(), 0);
assertEquals(expected.sum, stats.getSum(), TOLERANCE);
assertEquals(expected.min, stats.getMin(), 0);
assertEquals(expected.max, stats.getMax(), 0);
assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()),
stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()),
stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
}
);
}
示例14: stdDevBound
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的package包/类
double stdDevBound(ExtendedStats.Bounds bounds, double sigma) {
if (bounds == ExtendedStats.Bounds.UPPER) {
return (sum / count) + (Math.sqrt(variance()) * sigma);
} else {
return (sum / count) - (Math.sqrt(variance()) * sigma);
}
}
示例15: testEmptyAggregation
import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats; //导入依赖的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(extendedStats("stats").field("value")))
.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());
ExtendedStats stats = bucket.getAggregations().get("stats");
assertThat(stats, notNullValue());
assertThat(stats.getName(), equalTo("stats"));
assertThat(stats.getSumOfSquares(), equalTo(0.0));
assertThat(stats.getCount(), equalTo(0L));
assertThat(stats.getSum(), equalTo(0.0));
assertThat(stats.getMin(), equalTo(Double.POSITIVE_INFINITY));
assertThat(stats.getMax(), equalTo(Double.NEGATIVE_INFINITY));
assertThat(Double.isNaN(stats.getStdDeviation()), is(true));
assertThat(Double.isNaN(stats.getAvg()), is(true));
assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER)), is(true));
assertThat(Double.isNaN(stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER)), is(true));
}