Skip to content

Re-enable parallel collection for field sorted top hits #125916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 5 additions & 0 deletions docs/changelog/125916.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 125916
summary: Re-enable parallel collection for field sorted top hits
area: Search
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.ToLongFunction;

public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHitsAggregationBuilder> {
public static final String NAME = "top_hits";
Expand Down Expand Up @@ -823,18 +822,4 @@ public String getType() {
public TransportVersion getMinimalSupportedVersion() {
return TransportVersions.ZERO;
}

@Override
public boolean supportsParallelCollection(ToLongFunction<String> fieldCardinalityResolver) {
if (sorts != null) {
// the implicit sorting is by _score, which supports parallel collection
for (SortBuilder<?> sortBuilder : sorts) {
if (sortBuilder.supportsParallelCollection() == false) {
return false;
}
}
}

return super.supportsParallelCollection(fieldCardinalityResolver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,11 @@ public FieldSortBuilder rewrite(QueryRewriteContext ctx) throws IOException {
}
return new FieldSortBuilder(this).setNestedSort(rewrite);
}

@Override
public boolean supportsParallelCollection() {
// Disable parallel collection for sort by field.
// It is supported but not optimized on the Lucene side to share info across collectors, and can cause regressions.
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,11 @@ public GeoDistanceSortBuilder rewrite(QueryRewriteContext ctx) throws IOExceptio
}
return new GeoDistanceSortBuilder(this).setNestedSort(rewrite);
}

@Override
public boolean supportsParallelCollection() {
// Disable parallel collection for sort by field.
// It is supported but not optimized on the Lucene side to share info across collectors, and can cause regressions.
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,4 @@ public TransportVersion getMinimalSupportedVersion() {
public ScoreSortBuilder rewrite(QueryRewriteContext ctx) {
return this;
}

@Override
public boolean supportsParallelCollection() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,4 @@ public ScriptSortBuilder rewrite(QueryRewriteContext ctx) throws IOException {
}
return new ScriptSortBuilder(this).setNestedSort(rewrite);
}

@Override
public boolean supportsParallelCollection() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,6 @@ public String toString() {
}

public boolean supportsParallelCollection() {
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public void testSupportsParallelCollection() {
{
SearchSourceBuilder searchSourceBuilder = newSearchSourceBuilder.get();
searchSourceBuilder.aggregation(new TopHitsAggregationBuilder("tophits").sort(SortBuilders.fieldSort("field")));
assertFalse(searchSourceBuilder.supportsParallelCollection(fieldCardinality));
assertTrue(searchSourceBuilder.supportsParallelCollection(fieldCardinality));
}
{
SearchSourceBuilder searchSourceBuilder = newSearchSourceBuilder.get();
Expand Down
Loading