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

Bug #42997 #48270

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,21 @@ protected ValuesSourceConfig<WithOrdinals> resolveConfig(QueryShardContext query

private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig<WithOrdinals> config) {
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
if (parentJoinFieldMapper != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be:

Suggested change
if (parentJoinFieldMapper != null) {
if (parentJoinFieldMapper == null) {

?

config.unmapped(true);
return;
}
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ?

Suggested change
if (parentIdFieldMapper != null) {
if (parentIdFieldMapper == null) {

parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType);
config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType));
} else {
config.unmapped(true);
return;
}
parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = queryShardContext.getForField(fieldType);
config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public void testNoDocs() throws IOException {
assertEquals(Double.POSITIVE_INFINITY, ((InternalMin) parentToChild.getAggregations().get("in_child")).getValue(),
Double.MIN_VALUE);
});
testCase(new MatchAllDocsQuery(), newSearcher(indexReader, false, true), parentToChild -> {
assertEquals(0, parentToChild.getDocCount());
assertEquals(Double.POSITIVE_INFINITY, ((InternalMin) parentToChild.getAggregations().get("in_child")).getValue(),
Double.MIN_VALUE);
}, null);
indexReader.close();
directory.close();
}
Expand Down Expand Up @@ -108,13 +113,29 @@ public void testParentChild() throws IOException {
assertTrue(JoinAggregationInspectionHelper.hasValue(child));
assertEquals(expectedMinValue, ((InternalMin) child.getAggregations().get("in_child")).getValue(), Double.MIN_VALUE);
});
testCase(new MatchAllDocsQuery(), indexSearcher, child -> {
int expectedTotalChildren = 0;
int expectedMinValue = Integer.MAX_VALUE;
for (Tuple<Integer, Integer> expectedValues : expectedParentChildRelations.values()) {
expectedTotalChildren += expectedValues.v1();
expectedMinValue = Math.min(expectedMinValue, expectedValues.v2());
}
assertEquals(expectedTotalChildren, child.getDocCount());
assertTrue(JoinAggregationInspectionHelper.hasValue(child));
assertEquals(expectedMinValue, ((InternalMin) child.getAggregations().get("in_child")).getValue(), Double.MIN_VALUE);
}, null);

for (String parent : expectedParentChildRelations.keySet()) {
testCase(new TermInSetQuery(IdFieldMapper.NAME, Uid.encodeId(parent)), indexSearcher, child -> {
assertEquals((long) expectedParentChildRelations.get(parent).v1(), child.getDocCount());
assertEquals(expectedParentChildRelations.get(parent).v2(),
((InternalMin) child.getAggregations().get("in_child")).getValue(), Double.MIN_VALUE);
});
testCase(new TermInSetQuery(IdFieldMapper.NAME, Uid.encodeId(parent)), indexSearcher, child -> {
assertEquals((long) expectedParentChildRelations.get(parent).v1(), child.getDocCount());
assertEquals(expectedParentChildRelations.get(parent).v2(),
((InternalMin) child.getAggregations().get("in_child")).getValue(), Double.MIN_VALUE);
}, null);
}
indexReader.close();
directory.close();
Expand Down Expand Up @@ -187,4 +208,13 @@ private void testCase(Query query, IndexSearcher indexSearcher, Consumer<Interna
InternalChildren result = search(indexSearcher, query, aggregationBuilder, fieldType);
verify.accept(result);
}

private void testCase(Query query, IndexSearcher indexSearcher, Consumer<InternalChildren> verify, MappedFieldType fieldType)
throws IOException {

ChildrenAggregationBuilder aggregationBuilder = new ChildrenAggregationBuilder("_name", CHILD_TYPE);
aggregationBuilder.subAggregation(new MinAggregationBuilder("in_child").field("number"));
InternalChildren result = search(indexSearcher, query, aggregationBuilder, fieldType);
verify.accept(result);
}
}