7777import static org .elasticsearch .index .query .QueryBuilders .existsQuery ;
7878import static org .elasticsearch .index .query .QueryBuilders .functionScoreQuery ;
7979import static org .elasticsearch .index .query .QueryBuilders .fuzzyQuery ;
80+ import static org .elasticsearch .index .query .QueryBuilders .matchBoolPrefixQuery ;
8081import static org .elasticsearch .index .query .QueryBuilders .matchPhrasePrefixQuery ;
8182import static org .elasticsearch .index .query .QueryBuilders .matchPhraseQuery ;
8283import static org .elasticsearch .index .query .QueryBuilders .matchQuery ;
@@ -3644,7 +3645,6 @@ public void testConstantKeywordFieldNoHighlightingWildcard() throws IOException
36443645 String index = "test" ;
36453646 String constantKeywordFieldName = "test_constant_keyword_field" ;
36463647 String constantValue = "constant_value" ;
3647- String partialConstantValueWithWildCard = "foobar*" ;
36483648
36493649 XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
36503650 assertAcked (prepareCreate (index ).setMapping (mappings ));
@@ -3775,6 +3775,25 @@ public void testConstantKeywordFieldAndOtherFieldsMatchHighlighted() throws IOEx
37753775
37763776 }
37773777
3778+ public void testConstantKeywordMultiMatchQuery () throws IOException {
3779+ String index = "test" ;
3780+ String constantKeywordFieldName = "test_constant_keyword_field" ;
3781+ String constantValue = "bar" ;
3782+
3783+ XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
3784+ assertAcked (prepareCreate (index ).setMapping (mappings ));
3785+
3786+ XContentBuilder document = jsonBuilder ().startObject ().field ("foo" , constantValue ).endObject ();
3787+ saveDocumentIntoIndex (index , "1" , document );
3788+
3789+ SearchResponse search = prepareConstantKeywordSearch (multiMatchQuery (constantValue , constantKeywordFieldName , "foo" ));
3790+
3791+ assertNoFailures (search );
3792+ assertHighlight (search , 0 , constantKeywordFieldName , 0 , 1 , equalTo ("<em>bar</em>" ));
3793+ assertHighlight (search , 0 , "foo" , 0 , 1 , equalTo ("<em>bar</em>" ));
3794+
3795+ }
3796+
37783797 public void testConstantKeywordMultipleHitsHighlighted () throws IOException {
37793798 String index = "test" ;
37803799 String constantKeywordFieldName = "test_constant_keyword_field" ;
@@ -3824,26 +3843,13 @@ public void testDoubleConstantKeywordJustOneHighlighted() throws IOException {
38243843 String firstConstantValue = "constant_value_1" ;
38253844 String secondConstantValue = "constant_value_2" ;
38263845
3827- XContentBuilder mappings = jsonBuilder ();
3828- mappings .startObject ();
3829- mappings .startObject ("_doc" )
3830- .startObject ("properties" )
3831- .startObject (firstConstantKeywordFieldName )
3832- .field ("type" , "constant_keyword" )
3833- .field ("value" , firstConstantValue )
3834- .endObject ()
3835- .startObject (secondConstantKeywordFieldName )
3836- .field ("type" , "constant_keyword" )
3837- .field ("value" , secondConstantValue )
3838- .endObject ()
3839- .startObject ("foo" )
3840- .field ("type" , "text" )
3841- .endObject ()
3842- .endObject ()
3843- .endObject ();
3844- mappings .endObject ();
3845-
3846- assertAcked (prepareCreate (index ).setMapping (mappings ));
3846+ XContentBuilder mappings = prepareDoubleConstantKeywordMappings (
3847+ firstConstantKeywordFieldName ,
3848+ firstConstantValue ,
3849+ secondConstantKeywordFieldName ,
3850+ secondConstantValue
3851+ );
3852+ prepareCreate (index ).setMapping (mappings ).get ();
38473853
38483854 XContentBuilder document = jsonBuilder ().startObject ().field ("foo" , "bar" ).endObject ();
38493855 saveDocumentIntoIndex (index , "1" , document );
@@ -3855,7 +3861,55 @@ public void testDoubleConstantKeywordJustOneHighlighted() throws IOException {
38553861 assertHighlight (search , 0 , firstConstantKeywordFieldName , 0 , 1 , equalTo ("<em>constant_value_1</em>" ));
38563862 }
38573863
3858- public void testConstantKeywordNestedShouldQuery () throws Exception {
3864+ public void testConstantKeywordBoolPrefixQueryJustOneHighlighted () throws IOException {
3865+ String index = "test" ;
3866+ String firstConstantKeywordFieldName = "test_constant_keyword_field_1" ;
3867+ String firstConstantValue = "constant_value_1" ;
3868+ String secondConstantKeywordFieldName = "test_constant_keyword_field_2" ;
3869+ String secondConstantValue = "constant_value_2" ;
3870+
3871+ XContentBuilder mappings = prepareDoubleConstantKeywordMappings (
3872+ firstConstantKeywordFieldName ,
3873+ firstConstantValue ,
3874+ secondConstantKeywordFieldName ,
3875+ secondConstantValue
3876+ );
3877+ assertAcked (prepareCreate (index ).setMapping (mappings ));
3878+
3879+ XContentBuilder document = jsonBuilder ().startObject ()
3880+ .field ("foo" , "bar" )
3881+ .field (firstConstantKeywordFieldName , firstConstantValue )
3882+ .endObject ();
3883+ saveDocumentIntoIndex (index , "1" , document );
3884+
3885+ SearchResponse search = prepareConstantKeywordSearch (matchBoolPrefixQuery (firstConstantKeywordFieldName , "constant_value_1" ));
3886+
3887+ assertNoFailures (search );
3888+ assertHighlight (search , 0 , firstConstantKeywordFieldName , 0 , 1 , equalTo ("<em>constant_value_1</em>" ));
3889+ assertNotHighlighted (search , 0 , secondConstantKeywordFieldName );
3890+ }
3891+
3892+ public void testConstantKeywordFieldMatchPhraseQuery () throws IOException {
3893+ String index = "test" ;
3894+ String constantKeywordFieldName = "test_constant_keyword_field" ;
3895+ String constantValue = "constant_value" ;
3896+
3897+ XContentBuilder mappings = prepareConstantKeywordMappings (constantKeywordFieldName , constantValue );
3898+ assertAcked (prepareCreate (index ).setMapping (mappings ));
3899+
3900+ XContentBuilder document = jsonBuilder ().startObject ()
3901+ .field ("foo" , "bar" )
3902+ .field (constantKeywordFieldName , constantValue )
3903+ .endObject ();
3904+ saveDocumentIntoIndex (index , "1" , document );
3905+
3906+ SearchResponse search = prepareConstantKeywordSearch (matchPhraseQuery (constantKeywordFieldName , constantValue ));
3907+
3908+ assertNoFailures (search );
3909+ assertHighlight (search , 0 , constantKeywordFieldName , 0 , 1 , equalTo ("<em>constant_value</em>" ));
3910+ }
3911+
3912+ public void testConstantKeywordNestedShouldBoolQuery () throws Exception {
38593913 String index = "test" ;
38603914 String constantKeywordFieldName = "test_constant_keyword_field" ;
38613915 String constantValue = "constant_value" ;
@@ -3872,7 +3926,7 @@ public void testConstantKeywordNestedShouldQuery() throws Exception {
38723926 assertHighlight (search , 0 , constantKeywordFieldName , 0 , 1 , equalTo ("<em>constant_value</em>" ));
38733927 }
38743928
3875- public void testConstantKeywordNestedMustQuery () throws Exception {
3929+ public void testConstantKeywordNestedMustBoolQuery () throws Exception {
38763930 String index = "test" ;
38773931 String constantKeywordFieldName = "test_constant_keyword_field" ;
38783932 String constantValue = "constant_value" ;
0 commit comments