replace ShardSearchRequest.FilterParser functional interface with CheckedFunction
This commit is contained in:
parent
a8a13bb46f
commit
ab144c418e
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.index.query.functionscore;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -29,5 +28,5 @@ import java.io.IOException;
|
|||
*/
|
||||
@FunctionalInterface
|
||||
public interface ScoreFunctionParser<FB extends ScoreFunctionBuilder<FB>> {
|
||||
FB fromXContent(QueryParseContext context) throws IOException, ParsingException;
|
||||
FB fromXContent(QueryParseContext context) throws IOException;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.breaker.CircuitBreaker;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
|
@ -87,6 +88,7 @@ import org.elasticsearch.index.get.GetStats;
|
|||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.merge.MergeStats;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.recovery.RecoveryStats;
|
||||
import org.elasticsearch.index.refresh.RefreshStats;
|
||||
|
@ -1251,7 +1253,7 @@ public class IndicesService extends AbstractLifecycleComponent
|
|||
public AliasFilter buildAliasFilter(ClusterState state, String index, String... expressions) {
|
||||
/* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch
|
||||
* of dependencies we pass in a function that can perform the parsing. */
|
||||
ShardSearchRequest.FilterParser filterParser = bytes -> {
|
||||
CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
|
||||
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) {
|
||||
return new QueryParseContext(parser).parseInnerQueryBuilder();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.internal;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -66,7 +67,7 @@ public final class AliasFilter implements Writeable {
|
|||
final IndexMetaData indexMetaData = context.getIndexSettings().getIndexMetaData();
|
||||
/* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch
|
||||
* of dependencies we pass in a function that can perform the parsing. */
|
||||
ShardSearchRequest.FilterParser filterParser = bytes -> {
|
||||
CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
|
||||
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(context.getXContentRegistry(), bytes)) {
|
||||
return context.newParseContext(parser).parseInnerQueryBuilder();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.search.internal;
|
|||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -88,17 +89,13 @@ public interface ShardSearchRequest {
|
|||
*/
|
||||
void rewrite(QueryShardContext context) throws IOException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FilterParser {
|
||||
QueryBuilder parse(byte[] bytes) throws IOException;
|
||||
}
|
||||
/**
|
||||
* Returns the filter associated with listed filtering aliases.
|
||||
* <p>
|
||||
* The list of filtering aliases should be obtained by calling MetaData.filteringAliases.
|
||||
* Returns <tt>null</tt> if no filtering is required.</p>
|
||||
*/
|
||||
static QueryBuilder parseAliasFilter(FilterParser filterParser,
|
||||
static QueryBuilder parseAliasFilter(CheckedFunction<byte[], QueryBuilder, IOException> filterParser,
|
||||
IndexMetaData metaData, String... aliasNames) {
|
||||
if (aliasNames == null || aliasNames.length == 0) {
|
||||
return null;
|
||||
|
@ -110,7 +107,7 @@ public interface ShardSearchRequest {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
return filterParser.parse(alias.filter().uncompressed());
|
||||
return filterParser.apply(alias.filter().uncompressed());
|
||||
} catch (IOException ex) {
|
||||
throw new AliasFilterParsingException(index, alias.getAlias(), "Invalid alias filter", ex);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
|
@ -161,7 +162,7 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase {
|
|||
}
|
||||
|
||||
public QueryBuilder aliasFilter(IndexMetaData indexMetaData, String... aliasNames) {
|
||||
ShardSearchRequest.FilterParser filterParser = bytes -> {
|
||||
CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
|
||||
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry(), bytes)) {
|
||||
return new QueryParseContext(parser).parseInnerQueryBuilder();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue