Skip to content

Commit 014c395

Browse files
committed
Verify that the sort field is specifically the TS timestamp
Only activate the time-series optimizations if the aggregation is both: * Within a time-series aggregation (ie. tsid and @timestamp ordered) * The geo_line sort field is @timestamp
1 parent 1a9fc9a commit 014c395

File tree

2 files changed

+236
-172
lines changed

2 files changed

+236
-172
lines changed

x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/GeoLineAggregatorFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.io.IOException;
2121
import java.util.Map;
2222

23+
import static org.elasticsearch.cluster.metadata.DataStream.TIMESTAMP_FIELD;
24+
import static org.elasticsearch.xpack.spatial.search.aggregations.GeoLineAggregationBuilder.SORT_FIELD;
25+
2326
final class GeoLineAggregatorFactory extends MultiValuesSourceAggregatorFactory {
2427

2528
private final boolean includeSort;
@@ -58,13 +61,20 @@ protected Aggregator doCreateInternal(
5861
Map<String, Object> metaData
5962
) throws IOException {
6063
GeoLineMultiValuesSource valuesSources = new GeoLineMultiValuesSource(configs);
61-
if (context.isInSortOrderExecutionRequired()) {
64+
if (context.isInSortOrderExecutionRequired() && isSortByTimestamp(configs)) {
65+
// We require both that this aggregation is a sub-aggregation of time-series, and that the sort field is '@timestamp'
6266
return new GeoLineAggregator.TimeSeries(name, valuesSources, context, parent, metaData, includeSort, sortOrder, size);
6367
} else {
6468
return new GeoLineAggregator.Normal(name, valuesSources, context, parent, metaData, includeSort, sortOrder, size);
6569
}
6670
}
6771

72+
private boolean isSortByTimestamp(Map<String, ValuesSourceConfig> configs) {
73+
ValuesSourceConfig sortConfig = configs.get(SORT_FIELD.getPreferredName());
74+
// TODO: for 'position' metric no sort field is required
75+
return sortConfig.fieldContext().field().equals(TIMESTAMP_FIELD.getName());
76+
}
77+
6878
@Override
6979
public String getStatsSubtype() {
7080
return configs.get(GeoLineAggregationBuilder.POINT_FIELD.getPreferredName()).valueSourceType().typeName();

0 commit comments

Comments
 (0)