Skip to content

Commit 61e6577

Browse files
committed
Added tests for queries nested inside other queries
1 parent 598e981 commit 61e6577

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,59 @@ public void testDoubleConstantKeywordJustOneHighlighted() throws IOException {
38533853
assertHighlight(search, 0, firstConstantKeywordFieldName, 0, 1, equalTo("<em>constant_value_1</em>"));
38543854
}
38553855

3856+
public void testConstantKeywordNestedShouldQuery() throws Exception {
3857+
String index = "test";
3858+
String constantKeywordFieldName = "test_constant_keyword_field";
3859+
String constantValue = "constant_value";
3860+
3861+
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
3862+
prepareCreate(index).setMapping(mappings).get();
3863+
3864+
XContentBuilder document = jsonBuilder().startObject().field("foo", "bar").endObject();
3865+
saveDocumentIntoIndex(index, "1", document);
3866+
3867+
SearchResponse search = prepareConstantKeywordSearch(boolQuery().should(matchQuery(constantKeywordFieldName, constantValue)));
3868+
3869+
assertNoFailures(search);
3870+
assertHighlight(search, 0, constantKeywordFieldName, 0, 1, equalTo("<em>constant_value</em>"));
3871+
}
3872+
3873+
public void testConstantKeywordNestedMustQuery() throws Exception {
3874+
String index = "test";
3875+
String constantKeywordFieldName = "test_constant_keyword_field";
3876+
String constantValue = "constant_value";
3877+
3878+
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
3879+
prepareCreate(index).setMapping(mappings).get();
3880+
3881+
XContentBuilder document = jsonBuilder().startObject().field("foo", "bar").endObject();
3882+
saveDocumentIntoIndex(index, "1", document);
3883+
3884+
SearchResponse search = prepareConstantKeywordSearch(boolQuery().must(matchQuery(constantKeywordFieldName, constantValue)));
3885+
3886+
assertNoFailures(search);
3887+
assertHighlight(search, 0, constantKeywordFieldName, 0, 1, equalTo("<em>constant_value</em>"));
3888+
}
3889+
3890+
public void testConstantKeywordNestedFilterQuery() throws Exception {
3891+
String index = "test";
3892+
String constantKeywordFieldName = "test_constant_keyword_field";
3893+
String constantValue = "constant_value";
3894+
3895+
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
3896+
prepareCreate(index).setMapping(mappings).get();
3897+
3898+
XContentBuilder document = jsonBuilder().startObject().field("foo", "bar").endObject();
3899+
saveDocumentIntoIndex(index, "1", document);
3900+
3901+
SearchResponse search = prepareConstantKeywordSearch(
3902+
boolQuery().filter(matchQuery(constantKeywordFieldName, constantValue)).should(matchQuery("foo", "bar"))
3903+
);
3904+
3905+
assertNoFailures(search);
3906+
assertHighlight(search, 0, constantKeywordFieldName, 0, 1, equalTo("<em>constant_value</em>"));
3907+
}
3908+
38563909
private XContentBuilder prepareConstantKeywordMappings(String constantKeywordFieldName, String constantValue) throws IOException {
38573910
XContentBuilder mappings = jsonBuilder();
38583911
mappings.startObject();

0 commit comments

Comments
 (0)