@@ -50,6 +50,10 @@ private static IndexSettings indexSettings(Settings settings) {
50
50
return new IndexSettings (newIndexMeta ("test" , settings ), Settings .EMPTY );
51
51
}
52
52
53
+ private static IndexSettings indexSettings (Settings settings , IndexVersion indexVersion ) {
54
+ return new IndexSettings (newIndexMeta ("test" , settings , indexVersion ), Settings .EMPTY );
55
+ }
56
+
53
57
public void testNoIndexSort () {
54
58
IndexSettings indexSettings = indexSettings (Settings .EMPTY );
55
59
assertFalse (indexSettings .getIndexSortConfig ().hasIndexSort ());
@@ -230,34 +234,150 @@ public void testSortMissingValueDateNanoFieldPre714() {
230
234
}
231
235
}
232
236
233
- public void testTimeSeriesMode () {
237
+ public void testLegacyTimeSeriesMode () {
234
238
IndexSettings indexSettings = indexSettings (
235
239
Settings .builder ()
236
240
.put (IndexSettings .MODE .getKey (), "time_series" )
237
241
.put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), "some_dimension" )
238
242
.put (IndexSettings .TIME_SERIES_START_TIME .getKey (), "2021-04-28T00:00:00Z" )
239
243
.put (IndexSettings .TIME_SERIES_END_TIME .getKey (), "2021-04-29T00:00:00Z" )
240
- .build ()
244
+ .build (),
245
+ IndexVersions .UPGRADE_TO_LUCENE_10_2_2
241
246
);
242
247
Sort sort = buildIndexSort (indexSettings , TimeSeriesIdFieldMapper .FIELD_TYPE , new DateFieldMapper .DateFieldType ("@timestamp" ));
243
248
assertThat (sort .getSort (), arrayWithSize (2 ));
244
249
assertThat (sort .getSort ()[0 ].getField (), equalTo ("_tsid" ));
245
250
assertThat (sort .getSort ()[1 ].getField (), equalTo ("@timestamp" ));
246
251
}
247
252
248
- public void testTimeSeriesModeNoTimestamp () {
253
+ public void testLegacyTimeSeriesModeNoTimestamp () {
249
254
IndexSettings indexSettings = indexSettings (
250
255
Settings .builder ()
251
256
.put (IndexSettings .MODE .getKey (), "time_series" )
252
257
.put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), "some_dimension" )
253
258
.put (IndexSettings .TIME_SERIES_START_TIME .getKey (), "2021-04-28T00:00:00Z" )
254
259
.put (IndexSettings .TIME_SERIES_END_TIME .getKey (), "2021-04-29T00:00:00Z" )
255
- .build ()
260
+ .build (),
261
+ IndexVersions .UPGRADE_TO_LUCENE_10_2_2
256
262
);
257
263
Exception e = expectThrows (IllegalArgumentException .class , () -> buildIndexSort (indexSettings , TimeSeriesIdFieldMapper .FIELD_TYPE ));
258
264
assertThat (e .getMessage (), equalTo ("unknown index sort field:[@timestamp] required by [index.mode=time_series]" ));
259
265
}
260
266
267
+ public void testTimeSeriesMode () {
268
+ IndexSettings indexSettings = indexSettings (
269
+ Settings .builder ()
270
+ .put (IndexSettings .MODE .getKey (), "time_series" )
271
+ .put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), "some_dimension" )
272
+ .put (IndexSettings .TIME_SERIES_START_TIME .getKey (), "2021-04-28T00:00:00Z" )
273
+ .put (IndexSettings .TIME_SERIES_END_TIME .getKey (), "2021-04-29T00:00:00Z" )
274
+ .build ()
275
+ );
276
+ assertFalse (indexSettings .getIndexSortConfig ().hasIndexSort ());
277
+ }
278
+
279
+ public void testLegacyLogsdbIndexSortWithArrays () {
280
+ Settings settings = Settings .builder ()
281
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
282
+ .putList ("index.sort.field" , "field1" , "field2" )
283
+ .putList ("index.sort.order" , "asc" , "desc" )
284
+ .putList ("index.sort.missing" , "_last" , "_first" )
285
+ .build ();
286
+ IndexSettings indexSettings = indexSettings (settings , IndexVersions .UPGRADE_TO_LUCENE_10_2_2 );
287
+ IndexSortConfig config = indexSettings .getIndexSortConfig ();
288
+ assertTrue (config .hasIndexSort ());
289
+ assertThat (config .sortSpecs .length , equalTo (2 ));
290
+
291
+ assertThat (config .sortSpecs [0 ].field , equalTo ("field1" ));
292
+ assertThat (config .sortSpecs [1 ].field , equalTo ("field2" ));
293
+ assertThat (config .sortSpecs [0 ].order , equalTo (SortOrder .ASC ));
294
+ assertThat (config .sortSpecs [1 ].order , equalTo (SortOrder .DESC ));
295
+ assertThat (config .sortSpecs [0 ].missingValue , equalTo ("_last" ));
296
+ assertThat (config .sortSpecs [1 ].missingValue , equalTo ("_first" ));
297
+ assertNull (config .sortSpecs [0 ].mode );
298
+ assertNull (config .sortSpecs [1 ].mode );
299
+ }
300
+
301
+ public void testLegacyLogsdbInvalidIndexSortOrder () {
302
+ final Settings settings = Settings .builder ()
303
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
304
+ .putList ("index.sort.order" , new String [] { "asc" , "desc" })
305
+ .build ();
306
+ IllegalArgumentException exc = expectThrows (IllegalArgumentException .class , () -> indexSettings (settings ));
307
+ assertThat (exc .getMessage (), containsString ("index.sort.field:[] index.sort.order:[asc, desc], size mismatch" ));
308
+ }
309
+
310
+ public void testLegacyLogsdbInvalidIndexSortMode () {
311
+ final Settings settings = Settings .builder ()
312
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
313
+ .putList ("index.sort.mode" , new String [] { "max" })
314
+ .build ();
315
+ IllegalArgumentException exc = expectThrows (IllegalArgumentException .class , () -> indexSettings (settings ));
316
+ assertThat (exc .getMessage (), containsString ("index.sort.field:[] index.sort.mode:[max], size mismatch" ));
317
+ }
318
+
319
+ public void testLegacyLogsdbInvalidIndexSortMissing () {
320
+ final Settings settings = Settings .builder ()
321
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
322
+ .putList ("index.sort.missing" , new String [] { "_last" , "_last" })
323
+ .build ();
324
+ IllegalArgumentException exc = expectThrows (IllegalArgumentException .class , () -> indexSettings (settings ));
325
+ assertThat (exc .getMessage (), containsString ("index.sort.field:[] index.sort.missing:[_last, _last], size mismatch" ));
326
+ }
327
+
328
+ public void testLegacyLogsdbIndexSortWithHostname () {
329
+ Settings settings = Settings .builder ()
330
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
331
+ .put (IndexSettings .LOGSDB_SORT_ON_HOST_NAME .getKey (), true )
332
+ .build ();
333
+ IndexSettings indexSettings = indexSettings (settings , IndexVersions .UPGRADE_TO_LUCENE_10_2_2 );
334
+ IndexSortConfig config = indexSettings .getIndexSortConfig ();
335
+ assertTrue (config .hasIndexSort ());
336
+ assertThat (config .sortSpecs .length , equalTo (2 ));
337
+
338
+ assertThat (config .sortSpecs [0 ].field , equalTo ("host.name" ));
339
+ assertThat (config .sortSpecs [1 ].field , equalTo ("@timestamp" ));
340
+ assertThat (config .sortSpecs [0 ].order , equalTo (SortOrder .ASC ));
341
+ assertThat (config .sortSpecs [1 ].order , equalTo (SortOrder .DESC ));
342
+ assertThat (config .sortSpecs [0 ].missingValue , equalTo ("_last" ));
343
+ assertNull (config .sortSpecs [1 ].missingValue );
344
+ assertThat (config .sortSpecs [0 ].mode , equalTo (MultiValueMode .MIN ));
345
+ assertNull (config .sortSpecs [1 ].mode );
346
+ }
347
+
348
+ public void testLegacyLogsdbIndexSortTimestampOnly () {
349
+ Settings settings = Settings .builder ()
350
+ .put (IndexSettings .MODE .getKey (), "logsdb" )
351
+ .put (IndexSettings .LOGSDB_SORT_ON_HOST_NAME .getKey (), false )
352
+ .build ();
353
+ IndexSettings indexSettings = indexSettings (settings , IndexVersions .UPGRADE_TO_LUCENE_10_2_2 );
354
+ IndexSortConfig config = indexSettings .getIndexSortConfig ();
355
+ assertTrue (config .hasIndexSort ());
356
+ assertThat (config .sortSpecs .length , equalTo (1 ));
357
+
358
+ assertThat (config .sortSpecs [0 ].field , equalTo ("@timestamp" ));
359
+ assertThat (config .sortSpecs [0 ].order , equalTo (SortOrder .DESC ));
360
+ assertNull (config .sortSpecs [0 ].missingValue );
361
+ assertNull (config .sortSpecs [0 ].mode );
362
+ }
363
+
364
+ public void testLegacyLogsdbIndexSortTimestampBWC () {
365
+ Settings settings = Settings .builder ().put (IndexSettings .MODE .getKey (), "logsdb" ).build ();
366
+ IndexSettings indexSettings = indexSettings (settings , IndexVersions .UPGRADE_TO_LUCENE_10_0_0 );
367
+ IndexSortConfig config = indexSettings .getIndexSortConfig ();
368
+ assertTrue (config .hasIndexSort ());
369
+ assertThat (config .sortSpecs .length , equalTo (2 ));
370
+
371
+ assertThat (config .sortSpecs [0 ].field , equalTo ("host.name" ));
372
+ assertThat (config .sortSpecs [1 ].field , equalTo ("@timestamp" ));
373
+ assertNull (config .sortSpecs [0 ].order );
374
+ assertNull (config .sortSpecs [1 ].order );
375
+ assertNull (config .sortSpecs [0 ].missingValue );
376
+ assertNull (config .sortSpecs [1 ].missingValue );
377
+ assertNull (config .sortSpecs [0 ].mode );
378
+ assertNull (config .sortSpecs [1 ].mode );
379
+ }
380
+
261
381
private Sort buildIndexSort (IndexSettings indexSettings , MappedFieldType ... mfts ) {
262
382
Map <String , MappedFieldType > lookup = Maps .newMapWithExpectedSize (mfts .length );
263
383
for (MappedFieldType mft : mfts ) {
0 commit comments