|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.util.Map; |
22 | 22 |
|
| 23 | +import static org.elasticsearch.cluster.metadata.DataStream.TIMESTAMP_FIELD; |
| 24 | +import static org.elasticsearch.xpack.spatial.search.aggregations.GeoLineAggregationBuilder.SORT_FIELD; |
| 25 | + |
23 | 26 | final class GeoLineAggregatorFactory extends MultiValuesSourceAggregatorFactory { |
24 | 27 |
|
25 | 28 | private final boolean includeSort; |
@@ -58,13 +61,20 @@ protected Aggregator doCreateInternal( |
58 | 61 | Map<String, Object> metaData |
59 | 62 | ) throws IOException { |
60 | 63 | 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' |
62 | 66 | return new GeoLineAggregator.TimeSeries(name, valuesSources, context, parent, metaData, includeSort, sortOrder, size); |
63 | 67 | } else { |
64 | 68 | return new GeoLineAggregator.Normal(name, valuesSources, context, parent, metaData, includeSort, sortOrder, size); |
65 | 69 | } |
66 | 70 | } |
67 | 71 |
|
| 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 | + |
68 | 78 | @Override |
69 | 79 | public String getStatsSubtype() { |
70 | 80 | return configs.get(GeoLineAggregationBuilder.POINT_FIELD.getPreferredName()).valueSourceType().typeName(); |
|
0 commit comments