Adding a null pointer check to fix index_prefix query (#2879)
* Adding a null pointer check to fix index_prefix query Signed-off-by: Vacha Shah <vachshah@amazon.com> * Adding test Signed-off-by: Vacha Shah <vachshah@amazon.com>
This commit is contained in:
parent
c4b684d3ae
commit
452e368bde
|
@ -583,7 +583,9 @@ public class TextFieldMapper extends ParametrizedFieldMapper {
|
|||
}
|
||||
Automaton automaton = Operations.concatenate(automata);
|
||||
AutomatonQuery query = new AutomatonQuery(new Term(name(), value + "*"), automaton);
|
||||
query.setRewriteMethod(method);
|
||||
if (method != null) {
|
||||
query.setRewriteMethod(method);
|
||||
}
|
||||
return new BooleanQuery.Builder().add(query, BooleanClause.Occur.SHOULD)
|
||||
.add(new TermQuery(new Term(parentField.name(), value)), BooleanClause.Occur.SHOULD)
|
||||
.build();
|
||||
|
|
|
@ -190,6 +190,17 @@ public class TextFieldTypeTests extends FieldTypeTestCase {
|
|||
);
|
||||
|
||||
assertThat(q, equalTo(expected));
|
||||
|
||||
q = ft.prefixQuery("g", null, false, randomMockShardContext());
|
||||
automaton = Operations.concatenate(Arrays.asList(Automata.makeChar('g'), Automata.makeAnyChar()));
|
||||
|
||||
expected = new ConstantScoreQuery(
|
||||
new BooleanQuery.Builder().add(new AutomatonQuery(new Term("field._index_prefix", "g*"), automaton), BooleanClause.Occur.SHOULD)
|
||||
.add(new TermQuery(new Term("field", "g")), BooleanClause.Occur.SHOULD)
|
||||
.build()
|
||||
);
|
||||
|
||||
assertThat(q, equalTo(expected));
|
||||
}
|
||||
|
||||
public void testFetchSourceValue() throws IOException {
|
||||
|
|
Loading…
Reference in New Issue