private Aggregation getHistogramAggregation(String aggregationName, JSONObject aggregateJson) { String field = aggregateJson.getString("field"); String interval = aggregateJson.getString("interval"); Long minDocumentCount = JSONUtil.getOptionalLong(aggregateJson, "minDocumentCount"); return new HistogramAggregation(aggregationName, field, interval, minDocumentCount); }
protected List<AggregationBuilder> getElasticsearchHistogramAggregations(HistogramAggregation agg) { List<AggregationBuilder> aggs = new ArrayList<>(); PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getFieldName()); if (propertyDefinition == null) { throw new VertexiumException("Could not find mapping for property: " + agg.getFieldName()); for (String propertyName : getPropertyNames(agg.getFieldName())) { String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromDeflatedPropertyName(propertyName); String aggName = createAggregationName(agg.getAggregationName(), visibilityHash); if (propertyDataType == Date.class) { DateHistogramBuilder dateAgg = AggregationBuilders.dateHistogram(aggName); dateAgg.field(propertyName); dateAgg.interval(new DateHistogram.Interval(agg.getInterval())); if (agg.getMinDocumentCount() != null) { dateAgg.minDocCount(agg.getMinDocumentCount()); if (agg.getExtendedBounds() != null) { HistogramAggregation.ExtendedBounds<?> bounds = agg.getExtendedBounds(); if (bounds.getMinMaxType().isAssignableFrom(Long.class)) { dateAgg.extendedBounds((Long) bounds.getMin(), (Long) bounds.getMax()); for (AbstractAggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) { dateAgg.subAggregation(subAgg); HistogramBuilder histogramAgg = AggregationBuilders.histogram(aggName); histogramAgg.field(propertyName); histogramAgg.interval(Long.parseLong(agg.getInterval())); if (agg.getMinDocumentCount() != null) { histogramAgg.minDocCount(agg.getMinDocumentCount());
private Map<Object, Long> queryGraphQueryWithHistogramAggregation( String propertyName, String interval, Long minDocCount, HistogramAggregation.ExtendedBounds extendedBounds, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); HistogramAggregation agg = new HistogramAggregation("hist-count", propertyName, interval, minDocCount); agg.setExtendedBounds(extendedBounds); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", HistogramAggregation.class.getName()); return null; } q.addAggregation(agg); return histogramBucketToMap(q.vertices().getAggregationResult("hist-count", HistogramResult.class).getBuckets()); }
protected List<AggregationBuilder> getElasticsearchHistogramAggregations(HistogramAggregation agg) { List<AggregationBuilder> aggs = new ArrayList<>(); PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getFieldName()); if (propertyDefinition == null) { throw new VertexiumException("Could not find mapping for property: " + agg.getFieldName()); for (String propertyName : getPropertyNames(agg.getFieldName())) { String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromDeflatedPropertyName(propertyName); String aggName = createAggregationName(agg.getAggregationName(), visibilityHash); if (propertyDataType == Date.class) { DateHistogramBuilder dateAgg = AggregationBuilders.dateHistogram(aggName); dateAgg.field(propertyName); String interval = agg.getInterval(); if (Pattern.matches("^[0-9\\.]+$", interval)) { interval += "ms"; if (agg.getMinDocumentCount() != null) { dateAgg.minDocCount(agg.getMinDocumentCount()); if (agg.getExtendedBounds() != null) { HistogramAggregation.ExtendedBounds<?> bounds = agg.getExtendedBounds(); if (bounds.getMinMaxType().isAssignableFrom(Long.class)) { dateAgg.extendedBounds((Long) bounds.getMin(), (Long) bounds.getMax()); for (AbstractAggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) { dateAgg.subAggregation(subAgg); HistogramBuilder histogramAgg = AggregationBuilders.histogram(aggName); histogramAgg.field(propertyName); histogramAgg.interval(Long.parseLong(agg.getInterval()));
private Map<Object, Long> queryGraphQueryWithHistogramAggregation( String propertyName, String interval, Long minDocCount, HistogramAggregation.ExtendedBounds extendedBounds, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); HistogramAggregation agg = new HistogramAggregation("hist-count", propertyName, interval, minDocCount); agg.setExtendedBounds(extendedBounds); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", HistogramAggregation.class.getName()); return null; } q.addAggregation(agg); return histogramBucketToMap(q.vertices().getAggregationResult("hist-count", HistogramResult.class).getBuckets()); }
protected List<AggregationBuilder> getElasticsearchHistogramAggregations(HistogramAggregation agg) { List<AggregationBuilder> aggs = new ArrayList<>(); PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getFieldName()); if (propertyDefinition == null) { throw new VertexiumException("Could not find mapping for property: " + agg.getFieldName()); for (String propertyName : getPropertyNames(agg.getFieldName())) { String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName); String aggName = createAggregationName(agg.getAggregationName(), visibilityHash); if (propertyDataType == Date.class) { DateHistogramAggregationBuilder dateAgg = AggregationBuilders.dateHistogram(aggName); dateAgg.field(propertyName); String interval = agg.getInterval(); if (Pattern.matches("^[0-9\\.]+$", interval)) { interval += "ms"; if (agg.getMinDocumentCount() != null) { dateAgg.minDocCount(agg.getMinDocumentCount()); if (agg.getExtendedBounds() != null) { HistogramAggregation.ExtendedBounds<?> bounds = agg.getExtendedBounds(); if (bounds.getMinMaxType().isAssignableFrom(Long.class)) { dateAgg.extendedBounds(new ExtendedBounds((Long) bounds.getMin(), (Long) bounds.getMax())); for (AggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) { dateAgg.subAggregation(subAgg); HistogramAggregationBuilder histogramAgg = AggregationBuilders.histogram(aggName); histogramAgg.field(propertyName); histogramAgg.interval(Double.parseDouble(agg.getInterval()));
protected List<AggregationBuilder> getElasticsearchHistogramAggregations(HistogramAggregation agg) { List<AggregationBuilder> aggs = new ArrayList<>(); PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getFieldName()); if (propertyDefinition == null) { throw new VertexiumException("Could not find mapping for property: " + agg.getFieldName()); for (String propertyName : getPropertyNames(agg.getFieldName())) { String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName); String aggName = createAggregationName(agg.getAggregationName(), visibilityHash); if (propertyDataType == Date.class) { DateHistogramAggregationBuilder dateAgg = AggregationBuilders.dateHistogram(aggName); dateAgg.field(propertyName); String interval = agg.getInterval(); if (Pattern.matches("^[0-9\\.]+$", interval)) { interval += "ms"; if (agg.getMinDocumentCount() != null) { dateAgg.minDocCount(agg.getMinDocumentCount()); if (agg.getExtendedBounds() != null) { HistogramAggregation.ExtendedBounds<?> bounds = agg.getExtendedBounds(); if (bounds.getMinMaxType().isAssignableFrom(Long.class)) { dateAgg.extendedBounds(new ExtendedBounds((Long) bounds.getMin(), (Long) bounds.getMax())); for (AggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) { dateAgg.subAggregation(subAgg); HistogramAggregationBuilder histogramAgg = AggregationBuilders.histogram(aggName); histogramAgg.field(propertyName); histogramAgg.interval(Double.parseDouble(agg.getInterval()));