diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java index b4b5c56afe0..6e5a9582af4 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/rest/action/RestGraphAction.java @@ -5,15 +5,6 @@ */ package org.elasticsearch.graph.rest.action; -import static org.elasticsearch.graph.action.GraphExploreAction.INSTANCE; -import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestRequest.Method.POST; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; @@ -39,6 +30,15 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestToXContentListener; +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import static org.elasticsearch.graph.action.GraphExploreAction.INSTANCE; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + /** * @see GraphExploreRequest */ @@ -128,7 +128,7 @@ public class RestGraphAction extends BaseRestHandler { } } else if (token == XContentParser.Token.START_OBJECT) { if (context.getParseFieldMatcher().match(fieldName, QUERY_FIELD)) { - currentHop.guidingQuery(context.parseInnerQueryBuilder()); + context.parseInnerQueryBuilder().ifPresent(currentHop::guidingQuery); } 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/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java index 1bd5519b0a4..f759543a3b6 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapper.java @@ -52,6 +52,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import static org.apache.lucene.search.BooleanClause.Occur.SHOULD; @@ -122,9 +123,11 @@ public class ShieldIndexSearcherWrapper extends IndexSearcherWrapper { for (BytesReference bytesReference : permissions.getQueries()) { QueryShardContext queryShardContext = copyQueryShardContext(this.queryShardContext); try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) { - QueryBuilder queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder(); - ParsedQuery parsedQuery = queryShardContext.toQuery(queryBuilder); - filter.add(parsedQuery.query(), SHOULD); + Optional queryBuilder = queryShardContext.newParseContext(parser).parseInnerQueryBuilder(); + if (queryBuilder.isPresent()) { + ParsedQuery parsedQuery = queryShardContext.toQuery(queryBuilder.get()); + filter.add(parsedQuery.query(), SHOULD); + } } } // at least one of the queries should match diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java index 2c6fb58c4bc..c65b4a2c0a6 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/ShieldIndexSearcherWrapperIntegrationTests.java @@ -39,6 +39,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; import java.util.Collections; +import java.util.Optional; import static java.util.Collections.singleton; import static java.util.Collections.singletonMap; @@ -138,7 +139,8 @@ public class ShieldIndexSearcherWrapperIntegrationTests extends ESTestCase { for (int i = 0; i < numValues; i++) { ParsedQuery parsedQuery = new ParsedQuery(new TermQuery(new Term("field", values[i]))); when(queryShardContext.newParseContext(any(XContentParser.class))).thenReturn(queryParseContext); - when(queryParseContext.parseInnerQueryBuilder()).thenReturn((QueryBuilder) new TermQueryBuilder("field", values[i])); + when(queryParseContext.parseInnerQueryBuilder()) + .thenReturn(Optional.of((QueryBuilder) new TermQueryBuilder("field", values[i]))); when(queryShardContext.toQuery(any(QueryBuilder.class))).thenReturn(parsedQuery); DirectoryReader wrappedDirectoryReader = wrapper.wrap(directoryReader); IndexSearcher indexSearcher = wrapper.wrap(new IndexSearcher(wrappedDirectoryReader));