@@ -369,11 +369,11 @@ public void testWithNoValueMultiValue() throws Exception {
369369 String timestampField = "@timestamp" ;
370370 String hostnameField = "host.name" ;
371371 long baseTimestamp = 1704067200000L ;
372+ int numRounds = 32 + random ().nextInt (32 );
373+ int numDocsPerRound = 64 + random ().nextInt (64 );
372374
373375 var config = getTimeSeriesIndexWriterConfig (hostnameField , timestampField );
374376 try (var dir = newDirectory (); var iw = new IndexWriter (dir , config )) {
375- int numRounds = 4 + random ().nextInt (28 );
376- int numDocsPerRound = 8 + random ().nextInt (56 );
377377 long [] gauge1Values = new long [] { 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 };
378378 String [] tags = new String [] { "tag_1" , "tag_2" , "tag_3" , "tag_4" , "tag_5" , "tag_6" , "tag_7" , "tag_8" };
379379 {
@@ -382,26 +382,27 @@ public void testWithNoValueMultiValue() throws Exception {
382382 int r = random ().nextInt (10 );
383383 for (int j = 0 ; j < numDocsPerRound ; j ++) {
384384 var d = new Document ();
385- String hostName = String .format (Locale .ROOT , "host-%03d" , i );
385+ // host in reverse, otherwise merging will detect that segments are already ordered and will use sequential docid
386+ // merger:
387+ String hostName = String .format (Locale .ROOT , "host-%03d" , numRounds - i );
386388 d .add (new SortedDocValuesField (hostnameField , new BytesRef (hostName )));
387389 // Index sorting doesn't work with NumericDocValuesField:
388390 d .add (new SortedNumericDocValuesField (timestampField , timestamp ++));
389391
390392 if (r % 10 == 5 ) {
391393 // sometimes no values
392394 } else if (r % 10 > 5 ) {
393- // often multiple values:
395+ // often single value:
396+ d .add (new SortedNumericDocValuesField ("gauge_1" , gauge1Values [j % gauge1Values .length ]));
397+ d .add (new SortedSetDocValuesField ("tags" , new BytesRef (tags [j % tags .length ])));
398+ } else {
399+ // otherwise multiple values:
394400 int numValues = 2 + random ().nextInt (4 );
395401 for (int k = 0 ; k < numValues ; k ++) {
396402 d .add (new SortedNumericDocValuesField ("gauge_1" , gauge1Values [(j + k ) % gauge1Values .length ]));
397403 d .add (new SortedSetDocValuesField ("tags" , new BytesRef (tags [(j + k ) % tags .length ])));
398404 }
399- } else {
400- // otherwise single value:
401- d .add (new SortedNumericDocValuesField ("gauge_1" , gauge1Values [j % gauge1Values .length ]));
402- d .add (new SortedSetDocValuesField ("tags" , new BytesRef (tags [j % tags .length ])));
403405 }
404-
405406 iw .addDocument (d );
406407 }
407408 iw .commit ();
@@ -424,10 +425,8 @@ public void testWithNoValueMultiValue() throws Exception {
424425 assertNotNull (tagsDV );
425426 for (int i = 0 ; i < numDocs ; i ++) {
426427 assertEquals (i , hostNameDV .nextDoc ());
427- int round = i / numDocsPerRound ;
428- String expectedHostName = String .format (Locale .ROOT , "host-%03d" , round );
429428 String actualHostName = hostNameDV .lookupOrd (hostNameDV .ordValue ()).utf8ToString ();
430- assertEquals ( expectedHostName , actualHostName );
429+ assertTrue ( "unexpected host name:" + actualHostName , actualHostName . startsWith ( "host-" ) );
431430
432431 assertEquals (i , timestampDV .nextDoc ());
433432 long timestamp = timestampDV .longValue ();
0 commit comments