@@ -442,6 +442,28 @@ public void testRecoverySourceWithLogs() throws IOException {
442
442
}
443
443
}
444
444
445
+ public void testRecoverySourceWithLogsCustom () throws IOException {
446
+ XContentBuilder mappings = topMapping (b -> b .startObject (SourceFieldMapper .NAME ).field ("mode" , "synthetic" ).endObject ());
447
+ {
448
+ Settings settings = Settings .builder ().put (IndexSettings .MODE .getKey (), IndexMode .LOGSDB .getName ()).build ();
449
+ MapperService mapperService = createMapperService (settings , mappings );
450
+ DocumentMapper docMapper = mapperService .documentMapper ();
451
+ ParsedDocument doc = docMapper .parse (source (b -> { b .field ("@timestamp" , "2012-02-13" ); }));
452
+ assertNotNull (doc .rootDoc ().getField ("_recovery_source" ));
453
+ assertThat (doc .rootDoc ().getField ("_recovery_source" ).binaryValue (), equalTo (new BytesRef ("{\" @timestamp\" :\" 2012-02-13\" }" )));
454
+ }
455
+ {
456
+ Settings settings = Settings .builder ()
457
+ .put (IndexSettings .MODE .getKey (), IndexMode .LOGSDB .getName ())
458
+ .put (INDICES_RECOVERY_SOURCE_ENABLED_SETTING .getKey (), false )
459
+ .build ();
460
+ MapperService mapperService = createMapperService (settings , mappings );
461
+ DocumentMapper docMapper = mapperService .documentMapper ();
462
+ ParsedDocument doc = docMapper .parse (source (b -> b .field ("@timestamp" , "2012-02-13" )));
463
+ assertNull (doc .rootDoc ().getField ("_recovery_source" ));
464
+ }
465
+ }
466
+
445
467
public void testRecoverySourceWithTimeSeries () throws IOException {
446
468
{
447
469
Settings settings = Settings .builder ()
@@ -477,4 +499,49 @@ public void testRecoverySourceWithTimeSeries() throws IOException {
477
499
assertNull (doc .rootDoc ().getField ("_recovery_source" ));
478
500
}
479
501
}
502
+
503
+ public void testRecoverySourceWithTimeSeriesCustom () throws IOException {
504
+ String mappings = """
505
+ {
506
+ "_doc" : {
507
+ "_source" : {
508
+ "mode" : "synthetic"
509
+ },
510
+ "properties": {
511
+ "field": {
512
+ "type": "keyword",
513
+ "time_series_dimension": true
514
+ }
515
+ }
516
+ }
517
+ }
518
+ """ ;
519
+ {
520
+ Settings settings = Settings .builder ()
521
+ .put (IndexSettings .MODE .getKey (), IndexMode .TIME_SERIES .getName ())
522
+ .put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), "field" )
523
+ .build ();
524
+ MapperService mapperService = createMapperService (settings , mappings );
525
+ DocumentMapper docMapper = mapperService .documentMapper ();
526
+ ParsedDocument doc = docMapper .parse (source ("123" , b -> b .field ("@timestamp" , "2012-02-13" ).field ("field" , "value1" ), null ));
527
+ assertNotNull (doc .rootDoc ().getField ("_recovery_source" ));
528
+ assertThat (
529
+ doc .rootDoc ().getField ("_recovery_source" ).binaryValue (),
530
+ equalTo (new BytesRef ("{\" @timestamp\" :\" 2012-02-13\" ,\" field\" :\" value1\" }" ))
531
+ );
532
+ }
533
+ {
534
+ Settings settings = Settings .builder ()
535
+ .put (IndexSettings .MODE .getKey (), IndexMode .TIME_SERIES .getName ())
536
+ .put (IndexMetadata .INDEX_ROUTING_PATH .getKey (), "field" )
537
+ .put (INDICES_RECOVERY_SOURCE_ENABLED_SETTING .getKey (), false )
538
+ .build ();
539
+ MapperService mapperService = createMapperService (settings , mappings );
540
+ DocumentMapper docMapper = mapperService .documentMapper ();
541
+ ParsedDocument doc = docMapper .parse (
542
+ source ("123" , b -> b .field ("@timestamp" , "2012-02-13" ).field ("field" , randomAlphaOfLength (5 )), null )
543
+ );
544
+ assertNull (doc .rootDoc ().getField ("_recovery_source" ));
545
+ }
546
+ }
480
547
}
0 commit comments