From 5118a7b9bf40d8fe9042604b635866c66ae468ff Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Wed, 27 Nov 2024 15:46:20 -0500 Subject: [PATCH] Rename QueryBuilderService, remove query name from inference metadata --- .../org/elasticsearch/TransportVersions.java | 1 - .../metadata/InferenceFieldMetadata.java | 38 +++---------------- ...java => InferenceQueryBuilderService.java} | 4 +- ... InferenceQueryBuilderServiceBuilder.java} | 8 ++-- .../index/query/MatchQueryBuilder.java | 4 +- .../index/query/QueryRewriteContext.java | 14 +++---- .../elasticsearch/indices/IndicesService.java | 10 ++--- .../mapper/SemanticTextFieldMapper.java | 10 +---- 8 files changed, 26 insertions(+), 63 deletions(-) rename server/src/main/java/org/elasticsearch/index/query/{QueryBuilderService.java => InferenceQueryBuilderService.java} (83%) rename server/src/main/java/org/elasticsearch/index/query/{QueryBuilderServiceBuilder.java => InferenceQueryBuilderServiceBuilder.java} (84%) diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 48e266ac65e39..688d2aaf905a6 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -206,7 +206,6 @@ static TransportVersion def(int id) { public static final TransportVersion INGEST_PIPELINE_CONFIGURATION_AS_MAP = def(8_797_00_0); public static final TransportVersion INDEXING_PRESSURE_THROTTLING_STATS = def(8_798_00_0); public static final TransportVersion REINDEX_DATA_STREAMS = def(8_799_00_0); - public static final TransportVersion INFERENCE_FIELD_METADATA_STORE_QUERY_NAME = def(8_800_00_0); /* * STOP! READ THIS FIRST! No, really, diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java index 7b9bcb833f428..9b7d51072d4ca 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java @@ -9,7 +9,6 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.TransportVersions; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.SimpleDiffable; import org.elasticsearch.common.io.stream.StreamInput; @@ -37,26 +36,17 @@ public final class InferenceFieldMetadata implements SimpleDiffable readDiffFrom(StreamInput in) throws IOException { return SimpleDiffable.readDiffFrom(InferenceFieldMetadata::new, in); } @@ -138,9 +116,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId); } builder.array(SOURCE_FIELDS_FIELD, sourceFields); - if (queryName != null) { - builder.field(QUERY_NAME_FIELD, queryName); - } return builder.endObject(); } @@ -163,8 +138,6 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws inferenceId = parser.text(); } else if (SEARCH_INFERENCE_ID_FIELD.equals(currentFieldName)) { searchInferenceId = parser.text(); - } else if (QUERY_NAME_FIELD.equals(currentFieldName)) { - queryName = parser.text(); } } else if (token == XContentParser.Token.START_ARRAY) { if (SOURCE_FIELDS_FIELD.equals(currentFieldName)) { @@ -184,8 +157,7 @@ public static InferenceFieldMetadata fromXContent(XContentParser parser) throws name, inferenceId, searchInferenceId == null ? inferenceId : searchInferenceId, - inputFields.toArray(String[]::new), - queryName + inputFields.toArray(String[]::new) ); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/QueryBuilderService.java b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java similarity index 83% rename from server/src/main/java/org/elasticsearch/index/query/QueryBuilderService.java rename to server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java index 4603ebb5ae5b6..fc6ebb2e7a71c 100644 --- a/server/src/main/java/org/elasticsearch/index/query/QueryBuilderService.java +++ b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java @@ -10,10 +10,10 @@ import java.util.function.BiFunction; -public class QueryBuilderService { +public class InferenceQueryBuilderService { private final BiFunction> defaultInferenceQueryBuilder; - QueryBuilderService(BiFunction> defaultInferenceQueryBuilder) { + InferenceQueryBuilderService(BiFunction> defaultInferenceQueryBuilder) { this.defaultInferenceQueryBuilder = defaultInferenceQueryBuilder; } diff --git a/server/src/main/java/org/elasticsearch/index/query/QueryBuilderServiceBuilder.java b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java similarity index 84% rename from server/src/main/java/org/elasticsearch/index/query/QueryBuilderServiceBuilder.java rename to server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java index fb59bdbcdb70c..5fec65839debf 100644 --- a/server/src/main/java/org/elasticsearch/index/query/QueryBuilderServiceBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java @@ -16,15 +16,15 @@ import java.util.Objects; import java.util.function.BiFunction; -public class QueryBuilderServiceBuilder { +public class InferenceQueryBuilderServiceBuilder { private PluginsService pluginsService; - public QueryBuilderServiceBuilder pluginsService(PluginsService pluginsService) { + public InferenceQueryBuilderServiceBuilder pluginsService(PluginsService pluginsService) { this.pluginsService = pluginsService; return this; } - public QueryBuilderService build() { + public InferenceQueryBuilderService build() { Objects.requireNonNull(pluginsService); List>> definedInferenceQueryBuilders = new ArrayList<>(); @@ -42,6 +42,6 @@ public QueryBuilderService build() { ); } - return new QueryBuilderService(definedInferenceQueryBuilders.getFirst()); + return new InferenceQueryBuilderService(definedInferenceQueryBuilders.getFirst()); } } diff --git a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java index fd53b4b727f24..e7feafe8bc047 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java @@ -411,13 +411,13 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws } private QueryBuilder createInferenceSubQuery( - QueryBuilderService queryBuilderService, + InferenceQueryBuilderService inferenceQueryBuilderService, String indexName, String fieldName, Object value ) { BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); - boolQueryBuilder.must(queryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString())); + boolQueryBuilder.must(inferenceQueryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString())); boolQueryBuilder.filter(new TermQueryBuilder(IndexFieldMapper.NAME, indexName)); return boolQueryBuilder; } diff --git a/server/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/server/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index e3bd8360c2a48..b0b76b24c5119 100644 --- a/server/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/server/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -70,7 +70,7 @@ public class QueryRewriteContext { protected Predicate allowedFields; private final ResolvedIndices resolvedIndices; private final PointInTimeBuilder pit; - private final QueryBuilderService queryBuilderService; + private final InferenceQueryBuilderService inferenceQueryBuilderService; public QueryRewriteContext( final XContentParserConfiguration parserConfiguration, @@ -88,7 +88,7 @@ public QueryRewriteContext( final ScriptCompiler scriptService, final ResolvedIndices resolvedIndices, final PointInTimeBuilder pit, - final QueryBuilderService queryBuilderService + final InferenceQueryBuilderService inferenceQueryBuilderService ) { this.parserConfiguration = parserConfiguration; @@ -107,7 +107,7 @@ public QueryRewriteContext( this.scriptService = scriptService; this.resolvedIndices = resolvedIndices; this.pit = pit; - this.queryBuilderService = queryBuilderService; + this.inferenceQueryBuilderService = inferenceQueryBuilderService; } public QueryRewriteContext(final XContentParserConfiguration parserConfiguration, final Client client, final LongSupplier nowInMillis) { @@ -137,7 +137,7 @@ public QueryRewriteContext( final LongSupplier nowInMillis, final ResolvedIndices resolvedIndices, final PointInTimeBuilder pit, - final QueryBuilderService queryBuilderService + final InferenceQueryBuilderService inferenceQueryBuilderService ) { this( parserConfiguration, @@ -155,7 +155,7 @@ public QueryRewriteContext( null, resolvedIndices, pit, - queryBuilderService + inferenceQueryBuilderService ); } @@ -435,7 +435,7 @@ public String getTierPreference() { return value.split(",")[0].trim(); } - public QueryBuilderService getQueryBuilderService() { - return queryBuilderService; + public InferenceQueryBuilderService getQueryBuilderService() { + return inferenceQueryBuilderService; } } diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index 9e076016f87f2..6ca76ea6ff053 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -108,8 +108,8 @@ import org.elasticsearch.index.query.CoordinatorRewriteContextProvider; import org.elasticsearch.index.query.DataRewriteContext; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilderService; -import org.elasticsearch.index.query.QueryBuilderServiceBuilder; +import org.elasticsearch.index.query.InferenceQueryBuilderService; +import org.elasticsearch.index.query.InferenceQueryBuilderServiceBuilder; import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.recovery.RecoveryStats; import org.elasticsearch.index.refresh.RefreshStats; @@ -263,7 +263,7 @@ public class IndicesService extends AbstractLifecycleComponent private final MapperMetrics mapperMetrics; private final PostRecoveryMerger postRecoveryMerger; private final List searchOperationListeners; - private final QueryBuilderService queryBuilderService; + private final InferenceQueryBuilderService inferenceQueryBuilderService; @Override protected void doStart() { @@ -382,7 +382,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon this.timestampFieldMapperService = new TimestampFieldMapperService(settings, threadPool, this); this.postRecoveryMerger = new PostRecoveryMerger(settings, threadPool.executor(ThreadPool.Names.FORCE_MERGE), this::getShardOrNull); this.searchOperationListeners = builder.searchOperationListener; - this.queryBuilderService = new QueryBuilderServiceBuilder().pluginsService(pluginsService).build(); + this.inferenceQueryBuilderService = new InferenceQueryBuilderServiceBuilder().pluginsService(pluginsService).build(); } private static final String DANGLING_INDICES_UPDATE_THREAD_NAME = "DanglingIndices#updateTask"; @@ -1769,7 +1769,7 @@ public AliasFilter buildAliasFilter(ClusterState state, String index, Set sourcePaths) { String[] copyFields = sourcePaths.toArray(String[]::new); // ensure consistent order Arrays.sort(copyFields); - return new InferenceFieldMetadata( - fullPath(), - fieldType().inferenceId, - fieldType().searchInferenceId, - copyFields, - SemanticQueryBuilder.NAME - ); + return new InferenceFieldMetadata(fullPath(), fieldType().inferenceId, fieldType().searchInferenceId, copyFields); } @Override