Fix bug in parent and child aggregators when parent field not defined (#57089) (#59074)

Adding null check for ParentJoinFieldMapper in ChildrenAggregationBuilder.joinFieldResolveConfig

Closes #42997

Co-authored-by: ParthPunkster <parthjain.pj1994@gmail.com>
This commit is contained in:
Nik Everett 2020-07-06 10:59:47 -04:00 committed by GitHub
parent 2a1635ad69
commit 2965c7fe12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 7 deletions

View File

@ -112,17 +112,25 @@ public class ChildrenAggregationBuilder extends ValuesSourceAggregationBuilder<C
@Override @Override
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) { protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
ValuesSourceConfig config; ValuesSourceConfig config;
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService()); ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false); if (parentJoinFieldMapper == null) {
if (parentIdFieldMapper != null) {
parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext);
} else {
// Unmapped field case // Unmapped field case
config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext); config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext);
return config;
} }
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper == null) {
// Unmapped field case
config = ValuesSourceConfig.resolveUnmapped(defaultValueSourceType(), queryShardContext);
return config;
}
parentFilter = parentIdFieldMapper.getParentFilter();
childFilter = parentIdFieldMapper.getChildFilter(childType);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
config = ValuesSourceConfig.resolveFieldOnly(fieldType, queryShardContext);
return config; return config;
} }

View File

@ -0,0 +1,24 @@
---
"unconfigured":
- do:
index:
index: test
refresh: true
body:
join:
name: question
body: <p>I have Windows 2003 server and i bought a new Windows 2008 server...,
title: Whats the best way to file transfer my site from server to a newer one?,
tags: [windows-server-2003, windows-server-2008, file-transfer]
- do:
search:
index: test
body:
size: 0
aggs:
to-answers:
children:
type: answer
- match: { hits.total.value: 1 }
- match: { aggregations.to-answers.doc_count: 0 }