Skip to content

Commit

Permalink
Adding a null pointer check to fix index_prefix query (#2879) (#2902)
Browse files Browse the repository at this point in the history
* Adding a null pointer check to fix index_prefix query

Signed-off-by: Vacha Shah <[email protected]>

* Adding test

Signed-off-by: Vacha Shah <[email protected]>
(cherry picked from commit 452e368)

Co-authored-by: Vacha Shah <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and VachaShah authored Apr 14, 2022
1 parent 9b389bc commit 7bd7f2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool
}
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ public void testIndexPrefixes() {
);

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 {
Expand Down

0 comments on commit 7bd7f2f

Please sign in to comment.