Skip to content

Commit d6bf1bb

Browse files
committed
added another test
1 parent 36fe8eb commit d6bf1bb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,6 +3653,45 @@ public void testConstantKeywordAndOtherFieldsMatchMultipleHitsHighlighted() thro
36533653
assertHighlight(search, 1, constantKeywordFieldName, 0, 1, equalTo("<em>%s</em>".formatted(constantValue)));
36543654
}
36553655

3656+
public void testDoubleConstantKeywordJustOneHighlighted() throws IOException {
3657+
String index = "test";
3658+
String firstConstantKeywordFieldName = "test_constant_keyword_field_1";
3659+
String secondConstantKeywordFieldName = "test_constant_keyword_field_2";
3660+
String firstConstantValue = "constant_value_1";
3661+
String secondConstantValue = "constant_value_2";
3662+
3663+
XContentBuilder mappings = jsonBuilder();
3664+
mappings.startObject();
3665+
mappings.startObject("_doc")
3666+
.startObject("properties")
3667+
.startObject(firstConstantKeywordFieldName)
3668+
.field("type", "constant_keyword")
3669+
.field("value", firstConstantValue)
3670+
.endObject()
3671+
.startObject(secondConstantKeywordFieldName)
3672+
.field("type", "constant_keyword")
3673+
.field("value", secondConstantValue)
3674+
.endObject()
3675+
.startObject("foo")
3676+
.field("type", "text")
3677+
.endObject()
3678+
.endObject()
3679+
.endObject();
3680+
mappings.endObject();
3681+
3682+
3683+
assertAcked(prepareCreate(index).setMapping(mappings));
3684+
3685+
XContentBuilder document = jsonBuilder().startObject().field("foo", "bar").endObject();
3686+
saveDocumentIntoIndex(index, "1", document);
3687+
3688+
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.queryStringQuery(firstConstantValue));
3689+
3690+
assertNoFailures(search);
3691+
assertEquals(1, search.getHits().getHits()[0].getHighlightFields().size());
3692+
assertHighlight(search, 0, firstConstantKeywordFieldName, 0, 1, equalTo("<em>%s</em>".formatted(firstConstantValue)));
3693+
}
3694+
36563695
private XContentBuilder prepareConstantKeywordMappings(String constantKeywordFieldName, String constantValue) throws IOException {
36573696
XContentBuilder mappings = jsonBuilder();
36583697
mappings.startObject();

0 commit comments

Comments
 (0)