diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index cb3fc623357..9caee9bacfb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -124,7 +124,7 @@ public class RestGraphAction extends XPackRestHandler { } } else if (token == XContentParser.Token.START_OBJECT) { if (context.getParseFieldMatcher().match(fieldName, QUERY_FIELD)) { - context.parseInnerQueryBuilder().ifPresent(currentHop::guidingQuery); + currentHop.guidingQuery(context.parseInnerQueryBuilder()); } else if (context.getParseFieldMatcher().match(fieldName, CONNECTIONS_FIELD)) { parseHop(parser, context, graphRequest.createNextHop(null), graphRequest); } else if (context.getParseFieldMatcher().match(fieldName, CONTROLS_FIELD)) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java index c32d9362300..ee99142a567 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java @@ -80,7 +80,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -158,13 +157,11 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper { QueryShardContext queryShardContext = queryShardContextProvider.apply(shardId); bytesReference = evaluateTemplate(bytesReference); try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) { - Optional queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder(); - if (queryBuilder.isPresent()) { - verifyRoleQuery(queryBuilder.get()); - failIfQueryUsesClient(scriptService, queryBuilder.get(), queryShardContext); - ParsedQuery parsedQuery = queryShardContext.toQuery(queryBuilder.get()); - filter.add(parsedQuery.query(), SHOULD); - } + QueryBuilder queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder(); + verifyRoleQuery(queryBuilder); + failIfQueryUsesClient(scriptService, queryBuilder, queryShardContext); + ParsedQuery parsedQuery = queryShardContext.toQuery(queryBuilder); + filter.add(parsedQuery.query(), SHOULD); } } // at least one of the queries should match diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperIntegrationTests.java index 341a2e31e63..fbef69f557f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/authz/accesscontrol/SecurityIndexSearcherWrapperIntegrationTests.java @@ -44,7 +44,6 @@ import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.xpack.security.authz.permission.FieldPermissions; import java.util.Collections; -import java.util.Optional; import static java.util.Collections.singleton; import static java.util.Collections.singletonMap; @@ -148,8 +147,7 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends ESTestCase { for (int i = 0; i < numValues; i++) { ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i]))); when(queryShardContext.newParseContext(anyParser())).thenReturn(queryParseContext); - when(queryParseContext.parseInnerQueryBuilder()) - .thenReturn(Optional.of(new TermQueryBuilder("field", values[i]))); + when(queryParseContext.parseInnerQueryBuilder()).thenReturn(new TermQueryBuilder("field", values[i])); when(queryShardContext.toQuery(new TermsQueryBuilder("field", values[i]))).thenReturn(parsedQuery); DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader); IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader));