Skip to content
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

[8.15] Fix leak in collapsing search results (#110927) #110939

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/110927.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 110927
summary: Fix leak in collapsing search results
area: Search
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,27 @@ public void testCollapseWithDocValueFields() {
}
);
}

public void testCollapseWithFields() {
final String indexName = "test_collapse";
createIndex(indexName);
final String collapseField = "collapse_field";
final String otherField = "other_field";
assertAcked(indicesAdmin().preparePutMapping(indexName).setSource(collapseField, "type=keyword", otherField, "type=keyword"));
index(indexName, "id_1_0", Map.of(collapseField, "value1", otherField, "other_value1"));
index(indexName, "id_1_1", Map.of(collapseField, "value1", otherField, "other_value2"));
index(indexName, "id_2_0", Map.of(collapseField, "value2", otherField, "other_value3"));
refresh(indexName);

assertNoFailuresAndResponse(
prepareSearch(indexName).setQuery(new MatchAllQueryBuilder())
.setFetchSource(false)
.addFetchField(otherField)
.setCollapse(new CollapseBuilder(collapseField).setInnerHits(new InnerHitBuilder("ih").setSize(2))),
searchResponse -> {
assertEquals(collapseField, searchResponse.getHits().getCollapseField());
assertEquals(Set.of(new BytesRef("value1"), new BytesRef("value2")), Set.of(searchResponse.getHits().getCollapseValues()));
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private void doRun() {
if (hit.getInnerHits() == null) {
hit.setInnerHits(Maps.newMapWithExpectedSize(innerHitBuilders.size()));
}
if (hit.isPooled() == false) {
// TODO: make this work pooled by forcing the hit itself to become pooled as needed here
innerHits = innerHits.asUnpooled();
}
hit.getInnerHits().put(innerHitBuilder.getName(), innerHits);
assert innerHits.isPooled() == false || hit.isPooled() : "pooled inner hits can only be added to a pooled hit";
innerHits.mustIncRef();
Expand Down