Adapt to api changes in es core, inner query parsing now return Optional<QueryBuilder>
Changes relate to elastic/elasticsearch#17624 Original commit: elastic/x-pack-elasticsearch@bd9d31a9ff
This commit is contained in:
parent
e996b78b04
commit
9774e5472a
|
@ -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)) {
|
||||
|
|
|
@ -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> 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
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue