@@ -3506,13 +3506,17 @@ public void testDisableHighlightIdField() throws Exception {
35063506 public void testConstantKeywordFieldHighlighting () throws IOException {
35073507 // check that constant_keyword highlighting works
35083508 String index = "test" ;
3509- String constantKeywordFieldName = "level" ;
3510- String constantValue = new RandomString (5 ).nextString ();
3509+ RandomString randomStringGenerator = new RandomString (5 );
3510+ String constantKeywordFieldName = randomStringGenerator .nextString ();
3511+ String constantValue = randomStringGenerator .nextString ();
35113512
35123513 XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
35133514 assertAcked (prepareCreate (index ).setMapping (mappings ));
35143515
3515- XContentBuilder document = jsonBuilder ().startObject ().field ("message" , "some text" ).field ("level" , constantValue ).endObject ();
3516+ XContentBuilder document = jsonBuilder ().startObject ()
3517+ .field ("foo" , "bar" )
3518+ .field (constantKeywordFieldName , constantValue )
3519+ .endObject ();
35163520 saveDocumentIntoIndex (index , "1" , document );
35173521
35183522 SearchResponse search = prepareConstantKeywordSearch (QueryBuilders .queryStringQuery (constantValue ));
@@ -3524,13 +3528,14 @@ public void testConstantKeywordFieldHighlighting() throws IOException {
35243528 public void testImplicitConstantKeywordFieldHighlighting () throws IOException {
35253529 // Constant field value is defined by the mapping
35263530 String index = "test" ;
3527- String constantKeywordFieldName = "level" ;
3528- String constantValue = new RandomString (5 ).nextString ();
3531+ RandomString randomStringGenerator = new RandomString (5 );
3532+ String constantKeywordFieldName = randomStringGenerator .nextString ();
3533+ String constantValue = randomStringGenerator .nextString ();
35293534
35303535 XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
35313536 assertAcked (prepareCreate (index ).setMapping (mappings ));
35323537
3533- XContentBuilder document = jsonBuilder ().startObject ().field ("message " , "some text " ).endObject ();
3538+ XContentBuilder document = jsonBuilder ().startObject ().field ("foo " , "bar " ).endObject ();
35343539 saveDocumentIntoIndex (index , "1" , document );
35353540
35363541 SearchResponse search = prepareConstantKeywordSearch (QueryBuilders .queryStringQuery (constantValue ));
@@ -3541,14 +3546,15 @@ public void testImplicitConstantKeywordFieldHighlighting() throws IOException {
35413546
35423547 public void testConstantKeywordFieldPartialNoHighlighting () throws IOException {
35433548 String index = "test" ;
3544- String constantKeywordFieldName = "level" ;
3545- String constantValue = new RandomString (5 ).nextString ();
3549+ RandomString randomStringGenerator = new RandomString (5 );
3550+ String constantKeywordFieldName = randomStringGenerator .nextString ();
3551+ String constantValue = randomStringGenerator .nextString ();
35463552 String partialConstantValue = constantValue .substring (0 , 3 );
35473553
35483554 XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
35493555 assertAcked (prepareCreate (index ).setMapping (mappings ));
35503556
3551- XContentBuilder document = jsonBuilder ().startObject ().field ("message " , "some text " ).endObject ();
3557+ XContentBuilder document = jsonBuilder ().startObject ().field ("foo " , "bar " ).endObject ();
35523558 saveDocumentIntoIndex (index , "1" , document );
35533559
35543560 SearchResponse search = prepareConstantKeywordSearch (QueryBuilders .queryStringQuery (partialConstantValue ));
@@ -3559,14 +3565,15 @@ public void testConstantKeywordFieldPartialNoHighlighting() throws IOException {
35593565
35603566 public void testConstantKeywordFieldPartialWithWildcardHighlighting () throws IOException {
35613567 String index = "test" ;
3562- String constantKeywordFieldName = "level" ;
3563- String constantValue = new RandomString (5 ).nextString ();
3568+ RandomString randomStringGenerator = new RandomString (5 );
3569+ String constantKeywordFieldName = randomStringGenerator .nextString ();
3570+ String constantValue = randomStringGenerator .nextString ();
35643571 String partialConstantValueWithWildCard = "%s*" .formatted (constantValue .substring (0 , 3 ));
35653572
35663573 XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
35673574 assertAcked (prepareCreate (index ).setMapping (mappings ));
35683575
3569- XContentBuilder document = jsonBuilder ().startObject ().field ("message " , "some text " ).endObject ();
3576+ XContentBuilder document = jsonBuilder ().startObject ().field ("foo " , "bar " ).endObject ();
35703577 saveDocumentIntoIndex (index , "1" , document );
35713578
35723579 SearchResponse search = prepareConstantKeywordSearch (QueryBuilders .queryStringQuery (partialConstantValueWithWildCard ));
@@ -3584,7 +3591,7 @@ private XContentBuilder prepareConstantKeywordMappings(String constantKeywordFie
35843591 .field ("type" , "constant_keyword" )
35853592 .field ("value" , constantValue )
35863593 .endObject ()
3587- .startObject ("message " )
3594+ .startObject ("foo " )
35883595 .field ("type" , "text" )
35893596 .endObject ()
35903597 .endObject ()
0 commit comments