Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Harden the circuit breaker and failure handle logic in query result consumer ([#19396](https://github.com/opensearch-project/OpenSearch/pull/19396))
- Fix case insensitive and escaped query on wildcard ([#16827](https://github.com/opensearch-project/OpenSearch/pull/16827))
- Fix array_index_out_of_bounds_exception with wildcard and aggregations ([#20842](https://github.com/opensearch-project/OpenSearch/pull/20842))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ static class WildcardMatchingQuery extends Query {
private final Query firstPhaseQuery;
private final Predicate<String> secondPhaseMatcher;
private final String patternString; // For toString
private final ValueFetcher valueFetcher;
private final Supplier<ValueFetcher> valueFetcherSupplier;
private final SearchLookup searchLookup;

WildcardMatchingQuery(String fieldName, Query firstPhaseQuery, String patternString) {
Expand All @@ -794,10 +794,10 @@ public WildcardMatchingQuery(
this.patternString = Objects.requireNonNull(patternString);
if (context != null) {
this.searchLookup = context.lookup();
this.valueFetcher = fieldType.valueFetcher(context, context.lookup(), null);
this.valueFetcherSupplier = () -> fieldType.valueFetcher(context, context.lookup(), null);
} else {
this.searchLookup = null;
this.valueFetcher = null;
this.valueFetcherSupplier = null;
}
}

Expand All @@ -806,14 +806,14 @@ private WildcardMatchingQuery(
Query firstPhaseQuery,
Predicate<String> secondPhaseMatcher,
String patternString,
ValueFetcher valueFetcher,
Supplier<ValueFetcher> valueFetcherSupplier,
SearchLookup searchLookup
) {
this.fieldName = fieldName;
this.firstPhaseQuery = firstPhaseQuery;
this.secondPhaseMatcher = secondPhaseMatcher;
this.patternString = patternString;
this.valueFetcher = valueFetcher;
this.valueFetcherSupplier = valueFetcherSupplier;
this.searchLookup = searchLookup;
}

Expand Down Expand Up @@ -851,7 +851,7 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
rewriteFirstPhase,
secondPhaseMatcher,
patternString,
valueFetcher,
valueFetcherSupplier,
searchLookup
);
}
Expand Down Expand Up @@ -884,6 +884,9 @@ public Scorer get(long leadCost) throws IOException {
Scorer approximateScorer = firstPhaseSupplier.get(leadCost);
DocIdSetIterator approximation = approximateScorer.iterator();
LeafSearchLookup leafSearchLookup = searchLookup.getLeafSearchLookup(context);
// Create a new ValueFetcher per thread.
// ValueFetcher.setNextReader is not thread safe.
final ValueFetcher valueFetcher = valueFetcherSupplier.get();
valueFetcher.setNextReader(context);

TwoPhaseIterator twoPhaseIterator = new TwoPhaseIterator(approximation) {
Expand Down
Loading