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

Revert "Pass parent filter to inner hit query (#13770)" #13896

Merged
merged 1 commit into from
May 30, 2024
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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix get field mapping API returns 404 error in mixed cluster with multiple versions ([#13624](https://github.com/opensearch-project/OpenSearch/pull/13624))
- Allow clearing `remote_store.compatibility_mode` setting ([#13646](https://github.com/opensearch-project/OpenSearch/pull/13646))
- Fix ReplicaShardBatchAllocator to batch shards without duplicates ([#13710](https://github.com/opensearch-project/OpenSearch/pull/13710))
- Pass parent filter to inner hit query ([#13770](https://github.com/opensearch-project/OpenSearch/pull/13770))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,32 +401,16 @@
}
}
String name = innerHitBuilder.getName() != null ? innerHitBuilder.getName() : nestedObjectMapper.fullPath();
ObjectMapper parentObjectMapper = queryShardContext.nestedScope().getObjectMapper();
BitSetProducer parentFilter;
if (parentObjectMapper == null) {
parentFilter = queryShardContext.bitsetFilter(Queries.newNonNestedFilter());
} else {
parentFilter = queryShardContext.bitsetFilter(parentObjectMapper.nestedTypeFilter());
}
BitSetProducer previousParentFilter = queryShardContext.getParentFilter();
try {
queryShardContext.setParentFilter(parentFilter);
queryShardContext.nestedScope().nextLevel(nestedObjectMapper);
try {
NestedInnerHitSubContext nestedInnerHits = new NestedInnerHitSubContext(
name,
parentSearchContext,
parentObjectMapper,
nestedObjectMapper
);
setupInnerHitsContext(queryShardContext, nestedInnerHits);
innerHitsContext.addInnerHitDefinition(nestedInnerHits);
} finally {
queryShardContext.nestedScope().previousLevel();
}
} finally {
queryShardContext.setParentFilter(previousParentFilter);
}
ObjectMapper parentObjectMapper = queryShardContext.nestedScope().nextLevel(nestedObjectMapper);
NestedInnerHitSubContext nestedInnerHits = new NestedInnerHitSubContext(

Check warning on line 405 in server/src/main/java/org/opensearch/index/query/NestedQueryBuilder.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/query/NestedQueryBuilder.java#L404-L405

Added lines #L404 - L405 were not covered by tests
name,
parentSearchContext,
parentObjectMapper,
nestedObjectMapper
);
setupInnerHitsContext(queryShardContext, nestedInnerHits);
queryShardContext.nestedScope().previousLevel();
innerHitsContext.addInnerHitDefinition(nestedInnerHits);

Check warning on line 413 in server/src/main/java/org/opensearch/index/query/NestedQueryBuilder.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/query/NestedQueryBuilder.java#L411-L413

Added lines #L411 - L413 were not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,41 +311,6 @@ public void testInlineLeafInnerHitsNestedQuery() throws Exception {
assertThat(innerHitBuilders.get(leafInnerHits.getName()), Matchers.notNullValue());
}

public void testParentFilterFromInlineLeafInnerHitsNestedQuery() throws Exception {
QueryShardContext queryShardContext = createShardContext();
SearchContext searchContext = mock(SearchContext.class);
when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);

MapperService mapperService = mock(MapperService.class);
IndexSettings settings = new IndexSettings(newIndexMeta("index", Settings.EMPTY), Settings.EMPTY);
when(mapperService.getIndexSettings()).thenReturn(settings);
when(searchContext.mapperService()).thenReturn(mapperService);

InnerHitBuilder leafInnerHits = randomNestedInnerHits();
leafInnerHits.setScriptFields(null);
leafInnerHits.setHighlightBuilder(null);

QueryBuilder innerQueryBuilder = spy(new MatchAllQueryBuilder());
when(innerQueryBuilder.toQuery(queryShardContext)).thenAnswer(invoke -> {
QueryShardContext context = invoke.getArgument(0);
if (context.getParentFilter() == null) {
throw new Exception("Expect parent filter to be non-null");
}
return invoke.callRealMethod();
});
NestedQueryBuilder query = new NestedQueryBuilder("nested1", innerQueryBuilder, ScoreMode.None);
query.innerHit(leafInnerHits);
final Map<String, InnerHitContextBuilder> innerHitBuilders = new HashMap<>();
final InnerHitsContext innerHitsContext = new InnerHitsContext();
query.extractInnerHitBuilders(innerHitBuilders);
assertThat(innerHitBuilders.size(), Matchers.equalTo(1));
assertTrue(innerHitBuilders.containsKey(leafInnerHits.getName()));
assertNull(queryShardContext.getParentFilter());
innerHitBuilders.get(leafInnerHits.getName()).build(searchContext, innerHitsContext);
assertNull(queryShardContext.getParentFilter());
verify(innerQueryBuilder).toQuery(queryShardContext);
}

public void testInlineLeafInnerHitsNestedQueryViaBoolQuery() {
InnerHitBuilder leafInnerHits = randomNestedInnerHits();
NestedQueryBuilder nestedQueryBuilder = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None).innerHit(
Expand Down
Loading