Skip to content

Commit

Permalink
Adding a null pointer check to fix index_prefix query (#2879) (#2903)
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 <vachshah@amazon.com>

* Adding test

Signed-off-by: Vacha Shah <vachshah@amazon.com>
(cherry picked from commit 452e368)

Co-authored-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and VachaShah authored Apr 14, 2022
1 parent f8cf3a2 commit 0cc4718
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 0cc4718

Please sign in to comment.