4040import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
4141import org .elasticsearch .common .xcontent .XContentBuilder ;
4242import org .elasticsearch .common .xcontent .XContentType ;
43+
4344import org .elasticsearch .search .SearchModule ;
4445import org .elasticsearch .test .rest .ESRestTestCase ;
4546import org .junit .After ;
5859import java .util .HashSet ;
5960import java .util .List ;
6061import java .util .Locale ;
62+
6163import java .util .Set ;
6264import java .util .concurrent .TimeUnit ;
6365
6466import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
67+
6568import static org .hamcrest .Matchers .greaterThan ;
6669import static org .hamcrest .core .Is .is ;
6770
@@ -152,7 +155,7 @@ public void removePipelines() throws IOException {
152155 deletePipeline (ContinuousTestCase .INGEST_PIPELINE );
153156 }
154157
155- @ AwaitsFix ( bugUrl = "https://github.com/elastic/elasticsearch/issues/66410" )
158+
156159 public void testContinousEvents () throws Exception {
157160 String sourceIndexName = ContinuousTestCase .CONTINUOUS_EVENTS_SOURCE_INDEX ;
158161 DecimalFormat numberFormat = new DecimalFormat ("000" , new DecimalFormatSymbols (Locale .ROOT ));
@@ -301,6 +304,8 @@ public void testContinousEvents() throws Exception {
301304 * index sorting, triggers query optimizations.
302305 */
303306 private void putIndex (String indexName , String dateType , boolean isDataStream ) throws IOException {
307+ List <String > sortedFields = Collections .emptyList ();
308+
304309 // create mapping and settings
305310 try (XContentBuilder builder = jsonBuilder ()) {
306311 builder .startObject ();
@@ -310,9 +315,8 @@ private void putIndex(String indexName, String dateType, boolean isDataStream) t
310315 if (randomBoolean ()) {
311316 builder .field ("codec" , "best_compression" );
312317 }
313- // TODO: crashes with assertions enabled in lucene
314- if (false && randomBoolean ()) {
315- List <String > sortedFields = new ArrayList <>(
318+ if (randomBoolean ()) {
319+ sortedFields = new ArrayList <>(
316320 // note: no index sort for geo_point
317321 randomUnique (() -> randomFrom ("event" , "metric" , "run" , "timestamp" ), randomIntBetween (1 , 3 ))
318322 );
@@ -336,11 +340,16 @@ private void putIndex(String indexName, String dateType, boolean isDataStream) t
336340 }
337341 builder .endObject ();
338342
343+ // gh#72741 : index sort does not support unsigned_long
344+ final String metricType = sortedFields .contains ("metric" )
345+ ? randomFrom ("integer" , "long" )
346+ : randomFrom ("integer" , "long" , "unsigned_long" );
347+
339348 builder .startObject ("event" )
340349 .field ("type" , "keyword" )
341350 .endObject ()
342351 .startObject ("metric" )
343- .field ("type" , randomFrom ( "integer" , "long" , "unsigned_long" ) )
352+ .field ("type" , metricType )
344353 .endObject ()
345354 .startObject ("location" )
346355 .field ("type" , "geo_point" )
@@ -397,8 +406,8 @@ private void putIndex(String indexName, String dateType, boolean isDataStream) t
397406 .endObject ()
398407 .endObject ();
399408
400- // random overlay of existing field
401- if (randomBoolean ()) {
409+ // random overlay of existing field, only if its not part of sorted fields
410+ if (sortedFields . contains ( "metric" ) == false && randomBoolean ()) {
402411 if (randomBoolean ()) {
403412 builder .startObject ("metric" ).field ("type" , "long" ).endObject ();
404413 } else {
@@ -475,6 +484,7 @@ private void createOrUpdatePipeline(String field, int run) throws IOException {
475484 putPipeline (new PutPipelineRequest (ContinuousTestCase .INGEST_PIPELINE , BytesReference .bytes (pipeline ), XContentType .JSON ))
476485 .isAcknowledged ()
477486 );
487+
478488 }
479489
480490 private GetTransformStatsResponse getTransformStats (String id ) throws IOException {
@@ -538,18 +548,21 @@ private void refreshIndex(String index) throws IOException {
538548 private AcknowledgedResponse putTransform (TransformConfig config ) throws IOException {
539549 try (RestHighLevelClient restClient = new TestRestHighLevelClient ()) {
540550 return restClient .transform ().putTransform (new PutTransformRequest (config ), RequestOptions .DEFAULT );
551+
541552 }
542553 }
543554
544555 private org .elasticsearch .action .support .master .AcknowledgedResponse putPipeline (PutPipelineRequest pipeline ) throws IOException {
545556 try (RestHighLevelClient restClient = new TestRestHighLevelClient ()) {
546557 return restClient .ingest ().putPipeline (pipeline , RequestOptions .DEFAULT );
558+
547559 }
548560 }
549561
550562 private org .elasticsearch .action .support .master .AcknowledgedResponse deletePipeline (String id ) throws IOException {
551563 try (RestHighLevelClient restClient = new TestRestHighLevelClient ()) {
552564 return restClient .ingest ().deletePipeline (new DeletePipelineRequest (id ), RequestOptions .DEFAULT );
565+
553566 }
554567 }
555568
@@ -562,6 +575,7 @@ private GetTransformResponse getTransforms() throws IOException {
562575 private StartTransformResponse startTransform (String id ) throws IOException {
563576 try (RestHighLevelClient restClient = new TestRestHighLevelClient ()) {
564577 return restClient .transform ().startTransform (new StartTransformRequest (id ), RequestOptions .DEFAULT );
578+
565579 }
566580 }
567581
@@ -570,6 +584,7 @@ private StopTransformResponse stopTransform(String id, boolean waitForCompletion
570584 try (RestHighLevelClient restClient = new TestRestHighLevelClient ()) {
571585 return restClient .transform ()
572586 .stopTransform (new StopTransformRequest (id , waitForCompletion , timeout , waitForCheckpoint ), RequestOptions .DEFAULT );
587+
573588 }
574589 }
575590
@@ -578,6 +593,7 @@ private AcknowledgedResponse deleteTransform(String id, boolean force) throws IO
578593 DeleteTransformRequest deleteRequest = new DeleteTransformRequest (id );
579594 deleteRequest .setForce (force );
580595 return restClient .transform ().deleteTransform (deleteRequest , RequestOptions .DEFAULT );
596+
581597 }
582598 }
583599
@@ -599,4 +615,4 @@ private static class TestRestHighLevelClient extends RestHighLevelClient {
599615 super (client (), restClient -> {}, X_CONTENT_ENTRIES );
600616 }
601617 }
602- }
618+ }
0 commit comments