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 @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add pull-based ingestion error metrics and make internal queue size configurable ([#18088](https://github.com/opensearch-project/OpenSearch/pull/18088))
- Enabled Async Shard Batch Fetch by default ([#18139](https://github.com/opensearch-project/OpenSearch/pull/18139))
- Allow to get the search request from the QueryCoordinatorContext ([#17818](https://github.com/opensearch-project/OpenSearch/pull/17818))
- Improve sort-query performance by retaining the default `totalHitsThreshold` for approximated `match_all` queries ([#18189](https://github.com/opensearch-project/OpenSearch/pull/18189))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ public void testSortMissingNumbersMinMax() throws Exception {
.get();
assertNoFailures(searchResponse);

assertThat(searchResponse.getHits().getTotalHits().value(), equalTo(2L));
assertThat(searchResponse.getHits().getTotalHits().value(), equalTo(3L));
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));
// The order here could be unstable (depends on document order) since missing == field value
assertThat(searchResponse.getHits().getAt(1).getId(), is(oneOf("3", "2")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public boolean canApproximate(SearchContext context) {
if (context.from() + context.size() == 0) {
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);
} else {
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo() + 1));
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
}
if (context.request() != null && context.request().source() != null) {
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryVisitor;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Weight;
import org.opensearch.search.internal.SearchContext;

Expand Down Expand Up @@ -47,7 +48,11 @@
// Default to the original query. This suggests that we were not called from ContextIndexSearcher.
return originalQuery.rewrite(indexSearcher);
}
return resolvedQuery.rewrite(indexSearcher);
Query rewritten = resolvedQuery.rewrite(indexSearcher);
if (rewritten != resolvedQuery) {
resolvedQuery = rewritten;

Check warning on line 53 in server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java#L53

Added line #L53 was not covered by tests
}
return this;
}

public void setContext(SearchContext context) {
Expand Down Expand Up @@ -78,6 +83,15 @@
return true;
}

@Override
public Weight createWeight(IndexSearcher indexSearcher, ScoreMode scoreMode, float boost) throws IOException {
if (resolvedQuery == null) {
// Default to the original query.
return originalQuery.createWeight(indexSearcher, scoreMode, boost);

Check warning on line 90 in server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java#L90

Added line #L90 was not covered by tests
}
return resolvedQuery.createWeight(indexSearcher, scoreMode, boost);
}

@Override
public int hashCode() {
int h = classHash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.opensearch.common.util.CachedSupplier;
import org.opensearch.index.search.OpenSearchToParentBlockJoinQuery;
import org.opensearch.search.DocValueFormat;
import org.opensearch.search.approximate.ApproximateScoreQuery;
import org.opensearch.search.collapse.CollapseContext;
import org.opensearch.search.internal.ScrollContext;
import org.opensearch.search.internal.SearchContext;
Expand Down Expand Up @@ -724,6 +725,8 @@ static int shortcutTotalHitCount(IndexReader reader, Query query) throws IOExcep
query = ((ConstantScoreQuery) query).getQuery();
} else if (query instanceof BoostQuery) {
query = ((BoostQuery) query).getQuery();
} else if (query instanceof ApproximateScoreQuery) {
query = ((ApproximateScoreQuery) query).getOriginalQuery();
} else {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,20 @@ public void testRangeQuery() throws IOException {
String date2 = "2016-04-28T11:33:52";
long instant1 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date1)).toInstant().toEpochMilli();
long instant2 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date2)).toInstant().toEpochMilli() + 999;
Query expected = new ApproximatePointRangeQuery(
ApproximatePointRangeQuery approximatePointRangeQuery = new ApproximatePointRangeQuery(
"field",
pack(new long[] { instant1 }).bytes,
pack(new long[] { instant2 }).bytes,
new long[] { instant1 }.length,
ApproximatePointRangeQuery.LONG_FORMAT
);
Query expected = new ApproximateScoreQuery(
new IndexOrDocValuesQuery(
LongPoint.newRangeQuery("field", instant1, instant2),
SortedNumericDocValuesField.newSlowRangeQuery("field", instant1, instant2)
),
approximatePointRangeQuery
);
Query rangeQuery = ft.rangeQuery(date1, date2, true, true, null, null, null, context);
assertTrue(rangeQuery instanceof ApproximateScoreQuery);
((ApproximateScoreQuery) rangeQuery).setContext(new TestSearchContext(context));
Expand Down
Loading