Skip to content

Commit 841404f

Browse files
benwtrenthalilbulentorhonelasticmachine
authored
Fix analyzed wildcard query in simple_query_string when disjunctions is empty (#114264) (#114354)
This change fixes analyzed wildcard query in simple_query_string when disjunctions is empty. Closes #114185 (cherry picked from commit 6955bc1) Co-authored-by: Halil Bülent Orhon <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 6ead5f7 commit 841404f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/changelog/114264.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 114264
2+
summary: "Fix analyzed wildcard query in simple_query_string when disjunctions is empty"
3+
area: Search
4+
type: bug
5+
issues: [114185]

server/src/internalClusterTest/java/org/elasticsearch/search/query/SimpleQueryStringIT.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,32 @@ public void testFieldAliasOnDisallowedFieldType() throws Exception {
582582
});
583583
}
584584

585+
public void testSimpleQueryStringWithAnalysisStopWords() throws Exception {
586+
String mapping = Strings.toString(
587+
XContentFactory.jsonBuilder()
588+
.startObject()
589+
.startObject("properties")
590+
.startObject("body")
591+
.field("type", "text")
592+
.field("analyzer", "stop")
593+
.endObject()
594+
.endObject()
595+
.endObject()
596+
);
597+
598+
CreateIndexRequestBuilder mappingRequest = indicesAdmin().prepareCreate("test1").setMapping(mapping);
599+
mappingRequest.get();
600+
indexRandom(true, prepareIndex("test1").setId("1").setSource("body", "Some Text"));
601+
refresh();
602+
603+
assertHitCount(
604+
prepareSearch().setQuery(
605+
simpleQueryStringQuery("the* text*").analyzeWildcard(true).defaultOperator(Operator.AND).field("body")
606+
),
607+
1
608+
);
609+
}
610+
585611
private void assertHits(SearchHits hits, String... ids) {
586612
assertThat(hits.getTotalHits().value, equalTo((long) ids.length));
587613
Set<String> hitIds = new HashSet<>();

server/src/main/java/org/elasticsearch/index/search/SimpleQueryStringQueryParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ public Query newPrefixQuery(String text) {
199199
if (disjuncts.size() == 1) {
200200
return disjuncts.get(0);
201201
}
202+
if (disjuncts.size() == 0) {
203+
return null;
204+
}
202205
return new DisjunctionMaxQuery(disjuncts, 1.0f);
203206
}
204207

0 commit comments

Comments
 (0)