|
14 | 14 | import org.apache.lucene.search.SortedNumericSortField; |
15 | 15 | import org.apache.lucene.search.SortedSetSortField; |
16 | 16 | import org.elasticsearch.cluster.metadata.DataStream; |
| 17 | +import org.elasticsearch.common.logging.DeprecationCategory; |
| 18 | +import org.elasticsearch.common.logging.DeprecationLogger; |
17 | 19 | import org.elasticsearch.common.settings.Setting; |
18 | 20 | import org.elasticsearch.common.settings.Settings; |
19 | 21 | import org.elasticsearch.index.fielddata.IndexFieldData; |
|
53 | 55 | **/ |
54 | 56 | public final class IndexSortConfig { |
55 | 57 |
|
| 58 | + private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(IndexSortConfig.class); |
| 59 | + |
56 | 60 | /** |
57 | 61 | * The list of field names |
58 | 62 | */ |
@@ -134,10 +138,14 @@ private static MultiValueMode parseMultiValueMode(String value) { |
134 | 138 |
|
135 | 139 | // visible for tests |
136 | 140 | final FieldSortSpec[] sortSpecs; |
| 141 | + private final IndexVersion indexCreatedVersion; |
| 142 | + private final String indexName; |
137 | 143 | private final IndexMode indexMode; |
138 | 144 |
|
139 | 145 | public IndexSortConfig(IndexSettings indexSettings) { |
140 | 146 | final Settings settings = indexSettings.getSettings(); |
| 147 | + this.indexCreatedVersion = indexSettings.getIndexVersionCreated(); |
| 148 | + this.indexName = indexSettings.getIndex().getName(); |
141 | 149 | this.indexMode = indexSettings.getMode(); |
142 | 150 |
|
143 | 151 | if (this.indexMode == IndexMode.TIME_SERIES) { |
@@ -230,7 +238,22 @@ public Sort buildIndexSort( |
230 | 238 | throw new IllegalArgumentException(err); |
231 | 239 | } |
232 | 240 | if (Objects.equals(ft.name(), sortSpec.field) == false) { |
233 | | - throw new IllegalArgumentException("Cannot use alias [" + sortSpec.field + "] as an index sort field"); |
| 241 | + if (this.indexCreatedVersion.onOrAfter(IndexVersions.V_7_13_0)) { |
| 242 | + throw new IllegalArgumentException("Cannot use alias [" + sortSpec.field + "] as an index sort field"); |
| 243 | + } else { |
| 244 | + DEPRECATION_LOGGER.warn( |
| 245 | + DeprecationCategory.MAPPINGS, |
| 246 | + "index-sort-aliases", |
| 247 | + "Index sort for index [" |
| 248 | + + indexName |
| 249 | + + "] defined on field [" |
| 250 | + + sortSpec.field |
| 251 | + + "] which resolves to field [" |
| 252 | + + ft.name() |
| 253 | + + "]. " |
| 254 | + + "You will not be able to define an index sort over aliased fields in new indexes" |
| 255 | + ); |
| 256 | + } |
234 | 257 | } |
235 | 258 | boolean reverse = sortSpec.order == null ? false : (sortSpec.order == SortOrder.DESC); |
236 | 259 | MultiValueMode mode = sortSpec.mode; |
|
0 commit comments