Adapt to removal of support for empty queries

Original commit: elastic/x-pack-elasticsearch@87915a9cde
This commit is contained in:
javanna 2016-12-09 22:19:32 +01:00 committed by Luca Cavanna
parent 779eb44b66
commit 85679fcf19
3 changed files with 7 additions and 12 deletions

View File

@ -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)) {

View File

@ -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> 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

View File

@ -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));