mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-05 20:48:22 +00:00
Using non-mapped fields in prefix queries shouldn't cause NullPointerException
Fixes #2408
This commit is contained in:
parent
f47d62cc30
commit
120560bd0a
@ -109,7 +109,9 @@ public class PrefixQueryParser implements QueryParser {
|
||||
}
|
||||
if (query == null) {
|
||||
PrefixQuery prefixQuery = new PrefixQuery(new Term(fieldName, value));
|
||||
prefixQuery.setRewriteMethod(method);
|
||||
if (method != null) {
|
||||
prefixQuery.setRewriteMethod(method);
|
||||
}
|
||||
query = prefixQuery;
|
||||
}
|
||||
query.setBoost(boost);
|
||||
|
@ -617,6 +617,16 @@ public class SimpleIndexQueryParserTests {
|
||||
assertThat((double) prefixQuery.getBoost(), closeTo(2.0, 0.01));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixQueryWithUnknownField() throws IOException {
|
||||
IndexQueryParserService queryParser = queryParser();
|
||||
Query parsedQuery = queryParser.parse(prefixQuery("unknown", "sh")).query();
|
||||
assertThat(parsedQuery, instanceOf(PrefixQuery.class));
|
||||
PrefixQuery prefixQuery = (PrefixQuery) parsedQuery;
|
||||
assertThat(prefixQuery.getPrefix(), equalTo(new Term("unknown", "sh")));
|
||||
assertThat(prefixQuery.getRewriteMethod(), notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardQueryBuilder() throws IOException {
|
||||
IndexQueryParserService queryParser = queryParser();
|
||||
|
Loading…
x
Reference in New Issue
Block a user