org.elasticsearch.search.aggregations.bucket.nested.NestedBuilder Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.bucket.nested.NestedBuilder. 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: AggregationBuilders.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new {@link Nested} aggregation with the given name.
 */
public static NestedBuilder nested(String name) {
    return new NestedBuilder(name);
}
 
Example #2
Source File: AnalyticsServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public List<TimeseriesStatistics> getTraceCompletionTimeseriesStatistics(String tenantId, Criteria criteria, long interval) {
    String index = client.getIndex(tenantId);
    if (!refresh(index)) {
        return null;
    }

    StatsBuilder statsBuilder = AggregationBuilders
            .stats("stats")
            .field(ElasticsearchUtil.DURATION_FIELD);

    // TODO: HWKAPM-679 (related to HWKAPM-675), faults now recorded as properties. However this
    // current results in the fault count being an actual count of fault properties, where
    // the original intention of the fault count is the number of txns that have been affected
    // by a fault.
    FilterAggregationBuilder faultCountBuilder = AggregationBuilders
            .filter("faults")
            .filter(FilterBuilders.queryFilter(QueryBuilders.boolQuery()
                    .must(QueryBuilders.matchQuery(ElasticsearchUtil.PROPERTIES_NAME_FIELD, Constants.PROP_FAULT))));

    NestedBuilder nestedFaultCountBuilder = AggregationBuilders
            .nested("nested")
            .path(ElasticsearchUtil.PROPERTIES_FIELD)
            .subAggregation(faultCountBuilder);

    DateHistogramBuilder histogramBuilder = AggregationBuilders
            .dateHistogram("histogram")
            .interval(interval)
            .field(ElasticsearchUtil.TIMESTAMP_FIELD)
            .subAggregation(statsBuilder)
            .subAggregation(nestedFaultCountBuilder);

    BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, CompletionTime.class);
    SearchRequestBuilder request = getTraceCompletionRequest(index, criteria, query, 0)
            .addAggregation(histogramBuilder);

    SearchResponse response = getSearchResponse(request);
    DateHistogram histogram = response.getAggregations().get("histogram");

    return histogram.getBuckets().stream()
            .map(AnalyticsServiceElasticsearch::toTimeseriesStatistics)
            .collect(Collectors.toList());
}
 
Example #3
Source File: AnalyticsServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public List<TimeseriesStatistics> getEndpointResponseTimeseriesStatistics(String tenantId, Criteria criteria, long interval) {
    String index = client.getIndex(tenantId);
    if (!refresh(index)) {
        return null;
    }

    StatsBuilder statsBuilder = AggregationBuilders
            .stats("stats")
            .field(ElasticsearchUtil.ELAPSED_FIELD);

    // TODO: HWKAPM-679 (related to HWKAPM-675), faults now recorded as properties. However this
    // current results in the fault count being an actual count of fault properties, where
    // the original intention of the fault count is the number of txns that have been affected
    // by a fault.
    FilterAggregationBuilder faultCountBuilder = AggregationBuilders
            .filter("faults")
            .filter(FilterBuilders.queryFilter(QueryBuilders.boolQuery()
                    .must(QueryBuilders.matchQuery(ElasticsearchUtil.PROPERTIES_NAME_FIELD, Constants.PROP_FAULT))));

    NestedBuilder nestedFaultCountBuilder = AggregationBuilders
            .nested("nested")
            .path(ElasticsearchUtil.PROPERTIES_FIELD)
            .subAggregation(faultCountBuilder);

    DateHistogramBuilder histogramBuilder = AggregationBuilders
            .dateHistogram("histogram")
            .interval(interval)
            .field(ElasticsearchUtil.TIMESTAMP_FIELD)
            .subAggregation(statsBuilder)
            .subAggregation(nestedFaultCountBuilder);

    BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, NodeDetails.class);
    // Only interested in service endpoints, so just Consumer nodes
    query.must(QueryBuilders.termQuery(ElasticsearchUtil.TYPE_FIELD, "Consumer"));

    SearchRequestBuilder request = getNodeDetailsRequest(index, criteria, query, 0)
            .addAggregation(histogramBuilder);

    SearchResponse response = getSearchResponse(request);
    DateHistogram histogram = response.getAggregations().get("histogram");

    return histogram.getBuckets().stream()
            .map(AnalyticsServiceElasticsearch::toTimeseriesStatistics)
            .collect(Collectors.toList());
}
 
Example #4
Source File: SimpleSearchQueryBuilder.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public SimpleAggregationBuilder<SimpleSearchQueryBuilder> aggNested(String name, String path) {
	NestedBuilder nested = AggregationBuilders.nested(name).path(path);
	SimpleAggregationBuilder<SimpleSearchQueryBuilder> aggsBuilder = new SimpleAggregationBuilder<>(this, nested);
	this.searchQueryBuilder.addAggregation(aggsBuilder.aggsBuilder);
	return aggsBuilder;
}
 
Example #5
Source File: SimpleSearchQueryBuilder.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public SimpleAggregationBuilder<PB> subAggsNested(String name, String path) {
	NestedBuilder nested = AggregationBuilders.nested(name).path(path);
	SimpleAggregationBuilder<PB> subAggs = new SimpleAggregationBuilder<>(this.parentBuilder, nested);
	this.asAggregationBuilder().subAggregation(subAggs.aggsBuilder);
	return this;
}