Skip to content

Commit

Permalink
Remove explicit SearchResponse references from LegacyGeo, Aggregation…
Browse files Browse the repository at this point in the history
…s and parent-join modules
  • Loading branch information
iverase committed Oct 24, 2023
1 parent b0fb121 commit ceb506b
Show file tree
Hide file tree
Showing 11 changed files with 1,878 additions and 1,800 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.aggregations.AggregationIntegTestCase;
import org.elasticsearch.aggregations.bucket.timeseries.InternalTimeSeries;
Expand Down Expand Up @@ -42,6 +41,8 @@
import java.util.TreeSet;
import java.util.function.Supplier;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;

public class TimeSeriesNestedAggregationsIT extends AggregationIntegTestCase {
private static int numberOfDimensions;
private static int numberOfDocuments;
Expand Down Expand Up @@ -155,48 +156,56 @@ private static String formatDim(int dimId) {

public void testTimeSeriesAggregation() {
final TimeSeriesAggregationBuilder timeSeries = new TimeSeriesAggregationBuilder("ts");
final SearchResponse aggregationResponse = prepareSearch("index").addAggregation(timeSeries).setSize(0).get();
final InternalTimeSeries ts = (InternalTimeSeries) aggregationResponse.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
assertResponse(prepareSearch("index").addAggregation(timeSeries).setSize(0), response -> {
final InternalTimeSeries ts = (InternalTimeSeries) response.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
});
}

public void testSumByTsid() {
final TimeSeriesAggregationBuilder timeSeries = new TimeSeriesAggregationBuilder("ts").subAggregation(
new SumAggregationBuilder("sum").field("gauge_metric")
);
final SearchResponse searchResponse = prepareSearch("index").setQuery(new MatchAllQueryBuilder()).get();
assertNotEquals(numberOfDocuments, searchResponse.getHits().getHits().length);
final SearchResponse aggregationResponse = prepareSearch("index").addAggregation(timeSeries).setSize(0).get();
final InternalTimeSeries ts = (InternalTimeSeries) aggregationResponse.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
assertResponse(
prepareSearch("index").setQuery(new MatchAllQueryBuilder()),
response -> assertNotEquals(numberOfDocuments, response.getHits().getHits().length)
);

assertResponse(prepareSearch("index").addAggregation(timeSeries).setSize(0), response -> {
final InternalTimeSeries ts = (InternalTimeSeries) response.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
});
}

public void testTermsByTsid() {
final TimeSeriesAggregationBuilder timeSeries = new TimeSeriesAggregationBuilder("ts").subAggregation(
new TermsAggregationBuilder("terms").field("dim_0")
);
final SearchResponse aggregationResponse = prepareSearch("index").addAggregation(timeSeries).setSize(0).get();
final InternalTimeSeries ts = (InternalTimeSeries) aggregationResponse.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
assertResponse(prepareSearch("index").addAggregation(timeSeries).setSize(0), response -> {
final InternalTimeSeries ts = (InternalTimeSeries) response.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
});
}

public void testDateHistogramByTsid() {
final TimeSeriesAggregationBuilder timeSeries = new TimeSeriesAggregationBuilder("ts").subAggregation(
new DateHistogramAggregationBuilder("date_histogram").field("@timestamp").calendarInterval(DateHistogramInterval.HOUR)
);
final SearchResponse aggregationResponse = prepareSearch("index").addAggregation(timeSeries).setSize(0).get();
final InternalTimeSeries ts = (InternalTimeSeries) aggregationResponse.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
assertResponse(prepareSearch("index").addAggregation(timeSeries).setSize(0), response -> {
final InternalTimeSeries ts = (InternalTimeSeries) response.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
});
}

public void testCardinalityByTsid() {
final TimeSeriesAggregationBuilder timeSeries = new TimeSeriesAggregationBuilder("ts").subAggregation(
new CardinalityAggregationBuilder("dim_n_cardinality").field(formatDim(numberOfDimensions - 1))
);
final SearchResponse aggregationResponse = prepareSearch("index").addAggregation(timeSeries).setSize(0).get();
final InternalTimeSeries ts = (InternalTimeSeries) aggregationResponse.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
ts.getBuckets().forEach(bucket -> { assertCardinality(bucket.getAggregations().get("dim_n_cardinality"), 1); });
assertResponse(prepareSearch("index").addAggregation(timeSeries).setSize(0), response -> {
final InternalTimeSeries ts = (InternalTimeSeries) response.getAggregations().asList().get(0);
assertTimeSeriesAggregation(ts);
ts.getBuckets().forEach(bucket -> { assertCardinality(bucket.getAggregations().get("dim_n_cardinality"), 1); });
});
}

private static void assertTimeSeriesAggregation(final InternalTimeSeries timeSeriesAggregation) {
Expand Down
Loading

0 comments on commit ceb506b

Please sign in to comment.