Make sure to use nestedScope levels when building nested filters

This commit is contained in:
Christoph Büscher 2016-03-22 12:33:11 +01:00
parent 25da6b2f2e
commit 697174dcb0
3 changed files with 6 additions and 2 deletions

View File

@ -105,6 +105,7 @@ public class QueryShardContext extends QueryRewriteContext {
this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields();
this.indicesQueriesRegistry = indicesQueriesRegistry; this.indicesQueriesRegistry = indicesQueriesRegistry;
this.percolatorQueryCache = percolatorQueryCache; this.percolatorQueryCache = percolatorQueryCache;
this.nestedScope = new NestedScope();
} }
public QueryShardContext(QueryShardContext source) { public QueryShardContext(QueryShardContext source) {
@ -113,6 +114,7 @@ public class QueryShardContext extends QueryRewriteContext {
} }
@Override
public QueryShardContext clone() { public QueryShardContext clone() {
return new QueryShardContext(indexSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry, percolatorQueryCache); return new QueryShardContext(indexSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry, percolatorQueryCache);
} }

View File

@ -54,7 +54,9 @@ public abstract class SortBuilder<T extends SortBuilder<?>> implements ToXConten
} }
Query innerDocumentsQuery; Query innerDocumentsQuery;
if (nestedFilter != null) { if (nestedFilter != null) {
innerDocumentsQuery = nestedFilter.toFilter(context); context.nestedScope().nextLevel(nestedObjectMapper);
innerDocumentsQuery = QueryBuilder.rewriteQuery(nestedFilter, context).toFilter(context);
context.nestedScope().previousLevel();
} else { } else {
innerDocumentsQuery = nestedObjectMapper.nestedTypeFilter(); innerDocumentsQuery = nestedObjectMapper.nestedTypeFilter();
} }

View File

@ -242,7 +242,7 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T> & SortBuilde
} }
}); });
return new QueryShardContext(idxSettings, bitsetFilterCache, ifds, null, null, scriptService, return new QueryShardContext(idxSettings, bitsetFilterCache, ifds, null, null, scriptService,
indicesQueriesRegistry) { indicesQueriesRegistry, null) {
@Override @Override
public MappedFieldType fieldMapper(String name) { public MappedFieldType fieldMapper(String name) {
return provideMappedFieldType(name); return provideMappedFieldType(name);