本文整理了Java中org.elasticsearch.search.aggregations.bucket.histogram.Histogram
类的一些代码示例,展示了Histogram
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Histogram
类的具体详情如下:
包路径:org.elasticsearch.search.aggregations.bucket.histogram.Histogram
类名称:Histogram
[英]A histogram aggregation. Defines multiple buckets, each representing an interval in a histogram.
[中]直方图聚合。定义多个bucket,每个bucket表示直方图中的一个间隔。
代码示例来源:origin: SonarSource/sonarqube
private void processDateHistogram(Histogram aggregation) {
LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName());
for (Histogram.Bucket value : aggregation.getBuckets()) {
String day = dateTimeToDate(value.getKeyAsString(), timeZone);
if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
facet.put(day, Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
} else {
facet.put(day, value.getDocCount());
}
}
}
代码示例来源:origin: unchartedsoftware/aperture-tiles
private double getMaxValueFrom2DHistogram(Histogram agg) {
double maxValue = 1;
for (Histogram.Bucket bucket : agg.getBuckets()) {
Histogram yHistogram = bucket.getAggregations().get("yAgg");
// there could be no buckets, in which case
// there will be no effect on the max value
if (yHistogram.getBuckets().size() < 1){
continue;
}
// don't need to iterate over yAgg buckets because the query has ordered aggregations
// take the first one if it's greater than maxValue
if (maxValue < yHistogram.getBuckets().get(0).getDocCount() )
maxValue = yHistogram.getBuckets().get(0).getDocCount();
}
return maxValue;
}
代码示例来源:origin: unchartedsoftware/aperture-tiles
private Map<Integer, Map> parseAggregations(Histogram date_agg, TileIndex tileIndex) {
List<? extends Histogram.Bucket> dateBuckets = date_agg.getBuckets();
Map<Integer, Map> result = new HashMap<>();
long maxval = 0;
for (Histogram.Bucket dateBucket : dateBuckets) {
Histogram cluster_agg = dateBucket.getAggregations().get("yField");
List<? extends Histogram.Bucket> clusterBuckets = cluster_agg.getBuckets();
BinIndex xBinIndex = tilePyramid.rootToBin(dateBucket.getKeyAsNumber().doubleValue(), 0, tileIndex);
int xBin = xBinIndex.getX();
Map<Integer,Long> intermediate = new HashMap<>();
result.put(xBin, intermediate);
for( Histogram.Bucket clusterBucket : clusterBuckets) {
//given the bin coordinates, see if there's any data in those bins, add values to existing bins
BinIndex binIndex = tilePyramid.rootToBin(dateBucket.getKeyAsNumber().doubleValue(), clusterBucket.getKeyAsNumber().doubleValue(), tileIndex);
int yBin = binIndex.getY();
if (result.containsKey(xBin) && result.get(xBin).containsKey(yBin)) {
intermediate.put(yBin, (long) intermediate.get(yBin) + clusterBucket.getDocCount());
}
else if (result.containsKey(xBin) && !(intermediate.containsKey(yBin))) {
intermediate.put(yBin, clusterBucket.getDocCount());
}
if (maxval < clusterBucket.getDocCount()){
maxval = clusterBucket.getDocCount();
}
}
}
return result;
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
private void processHistogramAggregation(Histogram agg)
{
List<IntervalUnit> intervals = new ArrayList<>();
for (Histogram.Bucket h : agg.getBuckets()) {
ExtendedStats hStats = h.getAggregations().get(AbstractFacetRequest.INTERNAL_STATS);
if (hStats != null) {
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), hStats.getSum(), hStats.getAvg(), hStats.getMin(), hStats.getMax()));
} else {
intervals.add(new IntervalUnit(((DateTime) h.getKey()).getMillis(), h.getDocCount(), h.getDocCount(), 0, 0, 0, 0));
}
}
addFacet(new HistogramResult(agg.getName(), intervals));
}
}
代码示例来源:origin: org.neolumin.vertexium/vertexium-elasticsearch-base
@Override
public HistogramResult getHistogramResults(String name) {
List<HistogramBucket> buckets = new ArrayList<HistogramBucket>();
Aggregation agg = this.searchResponse.getAggregations().get(name);
if (agg == null) {
return null;
}
if (agg instanceof DateHistogram) {
DateHistogram h = (DateHistogram) agg;
for (DateHistogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKeyAsDate().toDate(), b.getDocCount()));
}
} else if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
for (Histogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKey(), b.getDocCount()));
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
return new HistogramResult(buckets);
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
private void processDateHistogram(Histogram aggregation) {
LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName());
for (Histogram.Bucket value : aggregation.getBuckets()) {
String day = dateTimeToDate(value.getKeyAsString(), timeZone);
if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
facet.put(day, Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
} else {
facet.put(day, value.getDocCount());
}
}
}
代码示例来源:origin: org.securegraph/securegraph-elasticsearch-base
@Override
public HistogramResult getHistogramResults(String name) {
List<HistogramBucket> buckets = new ArrayList<HistogramBucket>();
Aggregation agg = this.searchResponse.getAggregations().get(name);
if (agg == null) {
return null;
}
if (agg instanceof DateHistogram) {
DateHistogram h = (DateHistogram) agg;
for (DateHistogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKeyAsDate().toDate(), b.getDocCount()));
}
} else if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
for (Histogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKey(), b.getDocCount()));
}
} else {
throw new SecureGraphException("Aggregation is not a histogram: " + agg.getClass().getName());
}
return new HistogramResult(buckets);
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch5
private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().toString().equals("-1.0")) {
continue;
}
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {
@Override
protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new HistogramBucket(key, count, nestedResults);
}
@Override
protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
return new HistogramResult(buckets);
}
}.reduce(query, bucketsByKey);
}
代码示例来源:origin: lumifyio/securegraph
@Override
public HistogramResult getHistogramResults(String name) {
List<HistogramBucket> buckets = new ArrayList<HistogramBucket>();
Aggregation agg = this.searchResponse.getAggregations().get(name);
if (agg == null) {
return null;
}
if (agg instanceof DateHistogram) {
DateHistogram h = (DateHistogram) agg;
for (DateHistogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKeyAsDate().toDate(), b.getDocCount()));
}
} else if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
for (Histogram.Bucket b : h.getBuckets()) {
buckets.add(new HistogramBucket(b.getKey(), b.getDocCount()));
}
} else {
throw new SecureGraphException("Aggregation is not a histogram: " + agg.getClass().getName());
}
return new HistogramResult(buckets);
}
代码示例来源:origin: org.vertexium/vertexium-elasticsearch2
private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().toString().equals("-1")) {
continue;
}
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {
@Override
protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new HistogramBucket(key, count, nestedResults);
}
@Override
protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
return new HistogramResult(buckets);
}
}.reduce(query, bucketsByKey);
}
代码示例来源:origin: judasn/Elasticsearch-Tutorial-zh-CN
Iterator<org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket> groupByCreateDateTimeIterator = productGroupByPrice1.getBuckets().iterator();
while (groupByCreateDateTimeIterator.hasNext()) {
Histogram.Bucket groupByCreateDateTimeBucket = groupByCreateDateTimeIterator.next();
代码示例来源:origin: visallo/vertexium
private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
for (Aggregation agg : aggs) {
if (agg instanceof Histogram) {
Histogram h = (Histogram) agg;
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().toString().equals("-1.0")) {
continue;
}
List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
l.add(b);
}
} else {
throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
}
}
return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {
@Override
protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
return new HistogramBucket(key, count, nestedResults);
}
@Override
protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
return new HistogramResult(buckets);
}
}.reduce(query, bucketsByKey);
}
代码示例来源:origin: mbok/logsniffer
histogram.setEntries(new ArrayList<EventPersistence.HistogramEntry>());
if (response.getAggregations() != null) {
for (final Bucket e : ((Histogram) response.getAggregations().get("eventsCount")).getBuckets()) {
final DateTime key = (DateTime) e.getKey();
histogram.getEntries().add(new HistogramEntry(key.getMillis(), e.getDocCount()));
代码示例来源:origin: org.vertexium/vertexium-elasticsearch-singledocument
org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
for (Histogram.Bucket b : h.getBuckets()) {
if (isCalendarFieldQuery && b.getKey().equals("-1")) {
continue;
内容来源于网络,如有侵权,请联系作者删除!