diff --git a/server/src/main/resources/transport/definitions/referable/get_inference_fields_action_as_indices_action.csv b/server/src/main/resources/transport/definitions/referable/get_inference_fields_action_as_indices_action.csv
new file mode 100644
index 0000000000000..a8a5fda7760c2
--- /dev/null
+++ b/server/src/main/resources/transport/definitions/referable/get_inference_fields_action_as_indices_action.csv
@@ -0,0 +1 @@
+9260000,9250001
diff --git a/server/src/main/resources/transport/upper_bounds/9.3.csv b/server/src/main/resources/transport/upper_bounds/9.3.csv
index 94a47e0878c87..ea5804219d2b8 100644
--- a/server/src/main/resources/transport/upper_bounds/9.3.csv
+++ b/server/src/main/resources/transport/upper_bounds/9.3.csv
@@ -1 +1 @@
-initial_9.3.0,9250000
+get_inference_fields_action_as_indices_action,9250001
diff --git a/server/src/main/resources/transport/upper_bounds/9.4.csv b/server/src/main/resources/transport/upper_bounds/9.4.csv
new file mode 100644
index 0000000000000..d3954517fe8c3
--- /dev/null
+++ b/server/src/main/resources/transport/upper_bounds/9.4.csv
@@ -0,0 +1 @@
+get_inference_fields_action_as_indices_action,9260000
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsInternalAction.java
similarity index 83%
rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsAction.java
rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsInternalAction.java
index ddd1cbce9aa6d..ca1dcfd14a95a 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsAction.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/GetInferenceFieldsInternalAction.java
@@ -12,6 +12,7 @@
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
+import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.RemoteClusterActionType;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.metadata.IndexMetadata;
@@ -24,11 +25,11 @@
import org.elasticsearch.inference.InferenceResults;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
import static org.elasticsearch.action.ValidateActions.addValidationError;
@@ -42,20 +43,27 @@
* fields can be gathered more directly using {@link IndexMetadata#getMatchingInferenceFields}.
*
*/
-public class GetInferenceFieldsAction extends ActionType {
- public static final GetInferenceFieldsAction INSTANCE = new GetInferenceFieldsAction();
+public class GetInferenceFieldsInternalAction extends ActionType {
+ public static final GetInferenceFieldsInternalAction INSTANCE = new GetInferenceFieldsInternalAction();
public static final RemoteClusterActionType REMOTE_TYPE = new RemoteClusterActionType<>(INSTANCE.name(), Response::new);
+ // This is a defunct transport version for when GetInferenceFieldsInternalAction was an internal cluster action. This was the case only
+ // for 9.3.0 development builds, so there should be no real-world deployments using GetInferenceFieldsInternalAction as an internal
+ // cluster action. Therefore, this transport version can be disregarded.
public static final TransportVersion GET_INFERENCE_FIELDS_ACTION_TV = TransportVersion.fromName("get_inference_fields_action");
- public static final String NAME = "cluster:internal/xpack/inference/fields/get";
+ public static final TransportVersion GET_INFERENCE_FIELDS_ACTION_AS_INDICES_ACTION_TV = TransportVersion.fromName(
+ "get_inference_fields_action_as_indices_action"
+ );
- public GetInferenceFieldsAction() {
+ public static final String NAME = "indices:admin/inference/fields/get";
+
+ public GetInferenceFieldsInternalAction() {
super(NAME);
}
- public static class Request extends ActionRequest {
- private final Set indices;
+ public static class Request extends ActionRequest implements IndicesRequest.Replaceable {
+ private String[] indices;
private final Map fields;
private final boolean resolveWildcards;
private final boolean useDefaultFields;
@@ -63,10 +71,10 @@ public static class Request extends ActionRequest {
private final IndicesOptions indicesOptions;
/**
- * An overload of {@link #Request(Set, Map, boolean, boolean, String, IndicesOptions)} that uses {@link IndicesOptions#DEFAULT}
+ * An overload of {@link #Request(String[], Map, boolean, boolean, String, IndicesOptions)} that uses {@link IndicesOptions#DEFAULT}
*/
public Request(
- Set indices,
+ String[] indices,
Map fields,
boolean resolveWildcards,
boolean useDefaultFields,
@@ -97,7 +105,7 @@ public Request(
* @param indicesOptions The {@link IndicesOptions} to use when resolving indices.
*/
public Request(
- Set indices,
+ String[] indices,
Map fields,
boolean resolveWildcards,
boolean useDefaultFields,
@@ -114,7 +122,7 @@ public Request(
public Request(StreamInput in) throws IOException {
super(in);
- this.indices = in.readCollectionAsSet(StreamInput::readString);
+ this.indices = in.readStringArray();
this.fields = in.readMap(StreamInput::readFloat);
this.resolveWildcards = in.readBoolean();
this.useDefaultFields = in.readBoolean();
@@ -125,7 +133,7 @@ public Request(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
- out.writeStringCollection(indices);
+ out.writeStringArray(indices);
out.writeMap(fields, StreamOutput::writeFloat);
out.writeBoolean(resolveWildcards);
out.writeBoolean(useDefaultFields);
@@ -156,11 +164,18 @@ public ActionRequestValidationException validate() {
return validationException;
}
- public Set getIndices() {
- return Collections.unmodifiableSet(indices);
+ @Override
+ public Request indices(String... indices) {
+ this.indices = indices;
+ return this;
+ }
+
+ @Override
+ public String[] indices() {
+ return indices;
}
- public Map getFields() {
+ public Map fields() {
return Collections.unmodifiableMap(fields);
}
@@ -172,20 +187,26 @@ public boolean useDefaultFields() {
return useDefaultFields;
}
- public String getQuery() {
+ public String query() {
return query;
}
- public IndicesOptions getIndicesOptions() {
+ @Override
+ public IndicesOptions indicesOptions() {
return indicesOptions;
}
+ @Override
+ public boolean includeDataStreams() {
+ return true;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
- return Objects.equals(indices, request.indices)
+ return Arrays.equals(indices, request.indices)
&& Objects.equals(fields, request.fields)
&& resolveWildcards == request.resolveWildcards
&& useDefaultFields == request.useDefaultFields
@@ -195,7 +216,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
- return Objects.hash(indices, fields, resolveWildcards, useDefaultFields, query, indicesOptions);
+ return Objects.hash(Arrays.hashCode(indices), fields, resolveWildcards, useDefaultFields, query, indicesOptions);
}
}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java
index e1ae19acc4bb1..6a221d33041b5 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java
@@ -40,6 +40,7 @@
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
import org.elasticsearch.xpack.core.ccr.action.UnfollowAction;
import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction;
import org.elasticsearch.xpack.core.security.support.Automatons;
import org.elasticsearch.xpack.core.transform.action.GetCheckpointAction;
@@ -84,7 +85,8 @@ public final class IndexPrivilege extends Privilege {
private static final Automaton READ_AUTOMATON = patterns(
"indices:data/read/*",
ResolveIndexAction.NAME,
- TransportResolveClusterAction.NAME
+ TransportResolveClusterAction.NAME,
+ GetInferenceFieldsInternalAction.NAME // cross-cluster inference for semantic search
);
private static final Automaton READ_FAILURE_STORE_AUTOMATON = patterns("indices:data/read/*", ResolveIndexAction.NAME);
private static final Automaton READ_CROSS_CLUSTER_AUTOMATON = patterns(
diff --git a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsCrossClusterIT.java b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsCrossClusterIT.java
index fbb274c632c7a..df9ccdf0ae1f0 100644
--- a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsCrossClusterIT.java
+++ b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsCrossClusterIT.java
@@ -18,7 +18,7 @@
import org.elasticsearch.test.AbstractMultiClustersTestCase;
import org.elasticsearch.transport.RemoteClusterService;
import org.elasticsearch.xcontent.XContentBuilder;
-import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.ml.inference.results.TextExpansionResults;
import org.elasticsearch.xpack.inference.FakeMlPlugin;
import org.elasticsearch.xpack.inference.LocalStateInferencePlugin;
@@ -47,8 +47,6 @@ public class GetInferenceFieldsCrossClusterIT extends AbstractMultiClustersTestC
private static final String INFERENCE_ID = "test-inference-id";
private static final Map INFERENCE_ENDPOINT_SERVICE_SETTINGS = Map.of("model", "my_model", "api_key", "my_api_key");
- private boolean clustersConfigured = false;
-
@Override
protected List remoteClusterAlias() {
return List.of(REMOTE_CLUSTER);
@@ -71,23 +69,20 @@ protected Collection> nodePlugins(String clusterAlias) {
@Before
public void configureClusters() throws Exception {
- if (clustersConfigured == false) {
- setupTwoClusters();
- clustersConfigured = true;
- }
+ setupTwoClusters();
}
public void testRemoteIndex() {
- Consumer assertFailedRequest = r -> {
+ Consumer assertFailedRequest = r -> {
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
- () -> client().execute(GetInferenceFieldsAction.INSTANCE, r).actionGet(TEST_REQUEST_TIMEOUT)
+ () -> client().execute(GetInferenceFieldsInternalAction.INSTANCE, r).actionGet(TEST_REQUEST_TIMEOUT)
);
- assertThat(e.getMessage(), containsString("GetInferenceFieldsAction does not support remote indices"));
+ assertThat(e.getMessage(), containsString("GetInferenceFieldsInternalAction does not support remote indices"));
};
- var concreteIndexRequest = new GetInferenceFieldsAction.Request(
- Set.of(REMOTE_CLUSTER + ":test-index"),
+ var concreteIndexRequest = new GetInferenceFieldsInternalAction.Request(
+ new String[] { REMOTE_CLUSTER + ":test-index" },
Map.of(),
false,
false,
@@ -95,10 +90,22 @@ public void testRemoteIndex() {
);
assertFailedRequest.accept(concreteIndexRequest);
- var wildcardIndexRequest = new GetInferenceFieldsAction.Request(Set.of(REMOTE_CLUSTER + ":*"), Map.of(), false, false, "foo");
+ var wildcardIndexRequest = new GetInferenceFieldsInternalAction.Request(
+ new String[] { REMOTE_CLUSTER + ":*" },
+ Map.of(),
+ false,
+ false,
+ "foo"
+ );
assertFailedRequest.accept(wildcardIndexRequest);
- var wildcardClusterAndIndexRequest = new GetInferenceFieldsAction.Request(Set.of("*:*"), Map.of(), false, false, "foo");
+ var wildcardClusterAndIndexRequest = new GetInferenceFieldsInternalAction.Request(
+ new String[] { "*:*" },
+ Map.of(),
+ false,
+ false,
+ "foo"
+ );
assertFailedRequest.accept(wildcardClusterAndIndexRequest);
}
@@ -109,15 +116,15 @@ public void testRemoteClusterAction() {
RemoteClusterService.DisconnectedStrategy.RECONNECT_IF_DISCONNECTED
);
- var request = new GetInferenceFieldsAction.Request(
- Set.of(INDEX_NAME),
+ var request = new GetInferenceFieldsInternalAction.Request(
+ new String[] { INDEX_NAME },
generateDefaultWeightFieldMap(Set.of(INFERENCE_FIELD)),
false,
false,
"foo"
);
- PlainActionFuture future = new PlainActionFuture<>();
- remoteClusterClient.execute(GetInferenceFieldsAction.REMOTE_TYPE, request, future);
+ PlainActionFuture future = new PlainActionFuture<>();
+ remoteClusterClient.execute(GetInferenceFieldsInternalAction.REMOTE_TYPE, request, future);
var response = future.actionGet(TEST_REQUEST_TIMEOUT);
assertInferenceFieldsMap(
diff --git a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsIT.java b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsIT.java
index 26dd84509bb7b..8b15fecb33983 100644
--- a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsIT.java
+++ b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/GetInferenceFieldsIT.java
@@ -9,6 +9,7 @@
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.IndicesOptions;
+import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.IndexNotFoundException;
@@ -20,14 +21,13 @@
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
-import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.ml.inference.results.MlDenseEmbeddingResults;
import org.elasticsearch.xpack.core.ml.inference.results.TextExpansionResults;
import org.elasticsearch.xpack.inference.FakeMlPlugin;
import org.elasticsearch.xpack.inference.LocalStateInferencePlugin;
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
import org.elasticsearch.xpack.inference.mock.TestInferenceServicePlugin;
-import org.junit.Before;
import java.io.IOException;
import java.util.Collection;
@@ -51,7 +51,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
-@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE)
+@ESIntegTestCase.SuiteScopeTestCase
public class GetInferenceFieldsIT extends ESIntegTestCase {
private static final Map SPARSE_EMBEDDING_SERVICE_SETTINGS = Map.of("model", "my_model", "api_key", "my_api_key");
private static final Map TEXT_EMBEDDING_SERVICE_SETTINGS = Map.of(
@@ -70,7 +70,7 @@ public class GetInferenceFieldsIT extends ESIntegTestCase {
private static final String INDEX_1 = "index-1";
private static final String INDEX_2 = "index-2";
- private static final Set ALL_INDICES = Set.of(INDEX_1, INDEX_2);
+ private static final String[] ALL_INDICES = new String[] { INDEX_1, INDEX_2 };
private static final String INDEX_ALIAS = "index-alias";
private static final String INFERENCE_FIELD_1 = "inference-field-1";
@@ -105,8 +105,6 @@ public class GetInferenceFieldsIT extends ESIntegTestCase {
MlDenseEmbeddingResults.class
);
- private boolean clusterConfigured = false;
-
@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
return Settings.builder().put(LicenseSettings.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial").build();
@@ -117,13 +115,10 @@ protected Collection> nodePlugins() {
return List.of(LocalStateInferencePlugin.class, TestInferenceServicePlugin.class, FakeMlPlugin.class);
}
- @Before
- public void setUpCluster() throws Exception {
- if (clusterConfigured == false) {
- createInferenceEndpoints();
- createTestIndices();
- clusterConfigured = true;
- }
+ @Override
+ protected void setupSuiteScopeCluster() throws Exception {
+ createInferenceEndpoints();
+ createTestIndices();
}
public void testNullQuery() {
@@ -140,7 +135,7 @@ public void testBlankQuery() {
public void testFieldWeight() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
+ new GetInferenceFieldsInternalAction.Request(
ALL_INDICES,
Map.of(INFERENCE_FIELD_1, 2.0f, "inference-*", 1.5f, TEXT_FIELD_1, 1.75f),
false,
@@ -159,7 +154,7 @@ public void testFieldWeight() {
public void testNoInferenceFields() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
+ new GetInferenceFieldsInternalAction.Request(
ALL_INDICES,
generateDefaultWeightFieldMap(Set.of(TEXT_FIELD_1, TEXT_FIELD_2)),
false,
@@ -173,13 +168,13 @@ public void testNoInferenceFields() {
public void testResolveFieldWildcards() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("*")), true, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("*")), true, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
+ new GetInferenceFieldsInternalAction.Request(
ALL_INDICES,
Map.of("*-field-1", 2.0f, "*-1", 1.75f, "inference-*-3", 2.0f),
true,
@@ -204,39 +199,53 @@ public void testResolveFieldWildcards() {
public void testUseDefaultFields() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of(INDEX_1), Map.of(), true, true, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { INDEX_1 }, Map.of(), true, true, "foo"),
Map.of(INDEX_1, Set.of(new InferenceFieldWithTestMetadata(INFERENCE_FIELD_1, SPARSE_EMBEDDING_INFERENCE_ID, 5.0f))),
filterExpectedInferenceResults(ALL_EXPECTED_INFERENCE_RESULTS, Set.of(SPARSE_EMBEDDING_INFERENCE_ID))
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of(INDEX_2), Map.of(), true, true, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { INDEX_2 }, Map.of(), true, true, "foo"),
Map.of(INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
}
public void testMissingIndexName() {
- Set indicesWithIndex1 = Set.of(INDEX_1, "missing-index");
+ String[] indicesWithIndex1 = new String[] { INDEX_1, "missing-index" };
assertFailedRequest(
- new GetInferenceFieldsAction.Request(indicesWithIndex1, ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(indicesWithIndex1, ALL_FIELDS, false, false, "foo"),
IndexNotFoundException.class,
e -> assertThat(e.getMessage(), containsString("no such index [missing-index]"))
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(indicesWithIndex1, ALL_FIELDS, false, false, "foo", IndicesOptions.LENIENT_EXPAND_OPEN),
+ new GetInferenceFieldsInternalAction.Request(
+ indicesWithIndex1,
+ ALL_FIELDS,
+ false,
+ false,
+ "foo",
+ IndicesOptions.LENIENT_EXPAND_OPEN
+ ),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
- Set indicesWithoutIndex1 = Set.of("missing-index");
+ String[] indicesWithoutIndex1 = new String[] { "missing-index" };
assertFailedRequest(
- new GetInferenceFieldsAction.Request(indicesWithoutIndex1, ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(indicesWithoutIndex1, ALL_FIELDS, false, false, "foo"),
IndexNotFoundException.class,
e -> assertThat(e.getMessage(), containsString("no such index [missing-index]"))
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(indicesWithoutIndex1, ALL_FIELDS, false, false, "foo", IndicesOptions.LENIENT_EXPAND_OPEN),
+ new GetInferenceFieldsInternalAction.Request(
+ indicesWithoutIndex1,
+ ALL_FIELDS,
+ false,
+ false,
+ "foo",
+ IndicesOptions.LENIENT_EXPAND_OPEN
+ ),
Map.of(),
Map.of()
);
@@ -244,13 +253,25 @@ public void testMissingIndexName() {
public void testMissingFieldName() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("missing-field")), false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(
+ ALL_INDICES,
+ generateDefaultWeightFieldMap(Set.of("missing-field")),
+ false,
+ false,
+ "foo"
+ ),
Map.of(INDEX_1, Set.of(), INDEX_2, Set.of()),
Map.of()
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("missing-*")), true, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(
+ ALL_INDICES,
+ generateDefaultWeightFieldMap(Set.of("missing-*")),
+ true,
+ false,
+ "foo"
+ ),
Map.of(INDEX_1, Set.of(), INDEX_2, Set.of()),
Map.of()
);
@@ -259,14 +280,21 @@ public void testMissingFieldName() {
public void testNoIndices() {
// By default, an empty index set will be interpreted as _all
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of(), ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(Strings.EMPTY_ARRAY, ALL_FIELDS, false, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
// We can provide an IndicesOptions that changes this behavior to interpret an empty index set as no indices
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of(), ALL_FIELDS, false, false, "foo", IndicesOptions.STRICT_NO_EXPAND_FORBID_CLOSED),
+ new GetInferenceFieldsInternalAction.Request(
+ Strings.EMPTY_ARRAY,
+ ALL_FIELDS,
+ false,
+ false,
+ "foo",
+ IndicesOptions.STRICT_NO_EXPAND_FORBID_CLOSED
+ ),
Map.of(),
Map.of()
);
@@ -275,15 +303,15 @@ public void testNoIndices() {
public void testAllIndices() {
// By default, _all expands to all indices
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of("_all"), ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { "_all" }, ALL_FIELDS, false, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
// We can provide an IndicesOptions that changes this behavior to interpret it as no indices
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
- Set.of("_all"),
+ new GetInferenceFieldsInternalAction.Request(
+ new String[] { "_all" },
ALL_FIELDS,
false,
false,
@@ -297,7 +325,7 @@ public void testAllIndices() {
public void testIndexAlias() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of(INDEX_ALIAS), ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { INDEX_ALIAS }, ALL_FIELDS, false, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
@@ -305,20 +333,20 @@ public void testIndexAlias() {
public void testResolveIndexWildcards() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of("index-*"), ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { "index-*" }, ALL_FIELDS, false, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(Set.of("*-1"), ALL_FIELDS, false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(new String[] { "*-1" }, ALL_FIELDS, false, false, "foo"),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS),
ALL_EXPECTED_INFERENCE_RESULTS
);
assertFailedRequest(
- new GetInferenceFieldsAction.Request(
- Set.of("index-*"),
+ new GetInferenceFieldsInternalAction.Request(
+ new String[] { "index-*" },
ALL_FIELDS,
false,
false,
@@ -332,7 +360,7 @@ public void testResolveIndexWildcards() {
public void testNoFields() {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, Map.of(), false, false, "foo"),
+ new GetInferenceFieldsInternalAction.Request(ALL_INDICES, Map.of(), false, false, "foo"),
Map.of(INDEX_1, Set.of(), INDEX_2, Set.of()),
Map.of()
);
@@ -344,17 +372,17 @@ public void testInvalidRequest() {
);
assertFailedRequest(
- new GetInferenceFieldsAction.Request(null, Map.of(), false, false, null),
+ new GetInferenceFieldsInternalAction.Request(null, Map.of(), false, false, null),
ActionRequestValidationException.class,
e -> validator.accept(e, List.of("indices must not be null"))
);
assertFailedRequest(
- new GetInferenceFieldsAction.Request(Set.of(), null, false, false, null),
+ new GetInferenceFieldsInternalAction.Request(Strings.EMPTY_ARRAY, null, false, false, null),
ActionRequestValidationException.class,
e -> validator.accept(e, List.of("fields must not be null"))
);
assertFailedRequest(
- new GetInferenceFieldsAction.Request(null, null, false, false, null),
+ new GetInferenceFieldsInternalAction.Request(null, null, false, false, null),
ActionRequestValidationException.class,
e -> validator.accept(e, List.of("indices must not be null", "fields must not be null"))
);
@@ -362,7 +390,7 @@ public void testInvalidRequest() {
Map fields = new HashMap<>();
fields.put(INFERENCE_FIELD_1, null);
assertFailedRequest(
- new GetInferenceFieldsAction.Request(Set.of(), fields, false, false, null),
+ new GetInferenceFieldsInternalAction.Request(Strings.EMPTY_ARRAY, fields, false, false, null),
ActionRequestValidationException.class,
e -> validator.accept(e, List.of("weight for field [" + INFERENCE_FIELD_1 + "] must not be null"))
);
@@ -370,7 +398,7 @@ public void testInvalidRequest() {
private void explicitIndicesAndFieldsTestCase(String query) {
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, ALL_FIELDS, false, false, query),
+ new GetInferenceFieldsInternalAction.Request(ALL_INDICES, ALL_FIELDS, false, false, query),
Map.of(INDEX_1, INDEX_1_EXPECTED_INFERENCE_FIELDS, INDEX_2, INDEX_2_EXPECTED_INFERENCE_FIELDS),
query == null ? Map.of() : ALL_EXPECTED_INFERENCE_RESULTS
);
@@ -380,7 +408,7 @@ private void explicitIndicesAndFieldsTestCase(String query) {
Set.of(SPARSE_EMBEDDING_INFERENCE_ID)
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
+ new GetInferenceFieldsInternalAction.Request(
ALL_INDICES,
generateDefaultWeightFieldMap(Set.of(INFERENCE_FIELD_3)),
false,
@@ -397,8 +425,8 @@ private void explicitIndicesAndFieldsTestCase(String query) {
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(
- Set.of(INDEX_1),
+ new GetInferenceFieldsInternalAction.Request(
+ new String[] { INDEX_1 },
generateDefaultWeightFieldMap(Set.of(INFERENCE_FIELD_3)),
false,
false,
@@ -409,7 +437,7 @@ private void explicitIndicesAndFieldsTestCase(String query) {
);
assertSuccessfulRequest(
- new GetInferenceFieldsAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("*")), false, false, query),
+ new GetInferenceFieldsInternalAction.Request(ALL_INDICES, generateDefaultWeightFieldMap(Set.of("*")), false, false, query),
Map.of(INDEX_1, Set.of(), INDEX_2, Set.of()),
Map.of()
);
@@ -471,12 +499,12 @@ private void addTextField(String fieldName, XContentBuilder mapping) throws IOEx
mapping.endObject();
}
- private static GetInferenceFieldsAction.Response executeRequest(GetInferenceFieldsAction.Request request) {
- return client().execute(GetInferenceFieldsAction.INSTANCE, request).actionGet(TEST_REQUEST_TIMEOUT);
+ private static GetInferenceFieldsInternalAction.Response executeRequest(GetInferenceFieldsInternalAction.Request request) {
+ return client().execute(GetInferenceFieldsInternalAction.INSTANCE, request).actionGet(TEST_REQUEST_TIMEOUT);
}
private static void assertSuccessfulRequest(
- GetInferenceFieldsAction.Request request,
+ GetInferenceFieldsInternalAction.Request request,
Map> expectedInferenceFields,
Map> expectedInferenceResults
) {
@@ -486,7 +514,7 @@ private static void assertSuccessfulRequest(
}
private static void assertFailedRequest(
- GetInferenceFieldsAction.Request request,
+ GetInferenceFieldsInternalAction.Request request,
Class expectedException,
Consumer exceptionValidator
) {
@@ -495,13 +523,13 @@ private static void assertFailedRequest(
}
static void assertInferenceFieldsMap(
- Map> inferenceFieldsMap,
+ Map> inferenceFieldsMap,
Map> expectedInferenceFields
) {
assertThat(inferenceFieldsMap.size(), equalTo(expectedInferenceFields.size()));
for (var entry : inferenceFieldsMap.entrySet()) {
String indexName = entry.getKey();
- List indexInferenceFields = entry.getValue();
+ List indexInferenceFields = entry.getValue();
Set expectedIndexInferenceFields = expectedInferenceFields.get(indexName);
assertThat(expectedIndexInferenceFields, notNullValue());
diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java
index b7075fa6dc7f3..d8f8e84a38030 100644
--- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java
+++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java
@@ -67,7 +67,7 @@
import org.elasticsearch.xpack.core.inference.action.EmbeddingAction;
import org.elasticsearch.xpack.core.inference.action.GetCCMConfigurationAction;
import org.elasticsearch.xpack.core.inference.action.GetInferenceDiagnosticsAction;
-import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.inference.action.GetInferenceModelAction;
import org.elasticsearch.xpack.core.inference.action.GetInferenceServicesAction;
import org.elasticsearch.xpack.core.inference.action.GetRerankerWindowSizeAction;
@@ -84,7 +84,7 @@
import org.elasticsearch.xpack.inference.action.TransportEmbeddingAction;
import org.elasticsearch.xpack.inference.action.TransportGetCCMConfigurationAction;
import org.elasticsearch.xpack.inference.action.TransportGetInferenceDiagnosticsAction;
-import org.elasticsearch.xpack.inference.action.TransportGetInferenceFieldsAction;
+import org.elasticsearch.xpack.inference.action.TransportGetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.inference.action.TransportGetInferenceModelAction;
import org.elasticsearch.xpack.inference.action.TransportGetInferenceServicesAction;
import org.elasticsearch.xpack.inference.action.TransportGetRerankerWindowSizeAction;
@@ -289,7 +289,7 @@ public List getActions() {
new ActionHandler(DeleteCCMConfigurationAction.INSTANCE, TransportDeleteCCMConfigurationAction.class),
new ActionHandler(CCMCache.ClearCCMCacheAction.INSTANCE, CCMCache.ClearCCMCacheAction.class),
new ActionHandler(AuthorizationTaskExecutor.Action.INSTANCE, AuthorizationTaskExecutor.Action.class),
- new ActionHandler(GetInferenceFieldsAction.INSTANCE, TransportGetInferenceFieldsAction.class),
+ new ActionHandler(GetInferenceFieldsInternalAction.INSTANCE, TransportGetInferenceFieldsInternalAction.class),
new ActionHandler(EmbeddingAction.INSTANCE, TransportEmbeddingAction.class)
);
}
diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsAction.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsInternalAction.java
similarity index 79%
rename from x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsAction.java
rename to x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsInternalAction.java
index 57fd31fab754d..b791cf77f73c0 100644
--- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsAction.java
+++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceFieldsInternalAction.java
@@ -31,7 +31,7 @@
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.RemoteClusterAware;
import org.elasticsearch.transport.TransportService;
-import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.inference.action.InferenceAction;
import org.elasticsearch.xpack.core.ml.inference.results.ErrorInferenceResults;
@@ -45,9 +45,9 @@
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
-public class TransportGetInferenceFieldsAction extends HandledTransportAction<
- GetInferenceFieldsAction.Request,
- GetInferenceFieldsAction.Response> {
+public class TransportGetInferenceFieldsInternalAction extends HandledTransportAction<
+ GetInferenceFieldsInternalAction.Request,
+ GetInferenceFieldsInternalAction.Response> {
private final TransportService transportService;
private final ClusterService clusterService;
@@ -56,7 +56,7 @@ public class TransportGetInferenceFieldsAction extends HandledTransportAction<
private final Client client;
@Inject
- public TransportGetInferenceFieldsAction(
+ public TransportGetInferenceFieldsInternalAction(
TransportService transportService,
ActionFilters actionFilters,
ClusterService clusterService,
@@ -65,10 +65,10 @@ public TransportGetInferenceFieldsAction(
Client client
) {
super(
- GetInferenceFieldsAction.NAME,
+ GetInferenceFieldsInternalAction.NAME,
transportService,
actionFilters,
- GetInferenceFieldsAction.Request::new,
+ GetInferenceFieldsInternalAction.Request::new,
EsExecutors.DIRECT_EXECUTOR_SERVICE
);
this.transportService = transportService;
@@ -81,37 +81,33 @@ public TransportGetInferenceFieldsAction(
@Override
protected void doExecute(
Task task,
- GetInferenceFieldsAction.Request request,
- ActionListener listener
+ GetInferenceFieldsInternalAction.Request request,
+ ActionListener listener
) {
- final Set indices = request.getIndices();
- final Map fields = request.getFields();
+ final String[] indices = request.indices();
+ final Map fields = request.fields();
final boolean resolveWildcards = request.resolveWildcards();
final boolean useDefaultFields = request.useDefaultFields();
- final String query = request.getQuery();
- final IndicesOptions indicesOptions = request.getIndicesOptions();
+ final String query = request.query();
+ final IndicesOptions indicesOptions = request.indicesOptions();
try {
Map groupedIndices = transportService.getRemoteClusterService()
- .groupIndices(indicesOptions, indices.toArray(new String[0]), true);
+ .groupIndices(indicesOptions, indices, true);
OriginalIndices localIndices = groupedIndices.remove(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
if (groupedIndices.isEmpty() == false) {
- throw new IllegalArgumentException("GetInferenceFieldsAction does not support remote indices");
+ throw new IllegalArgumentException("GetInferenceFieldsInternalAction does not support remote indices");
}
ProjectState projectState = projectResolver.getProjectState(clusterService.state());
String[] concreteLocalIndices = indexNameExpressionResolver.concreteIndexNames(projectState.metadata(), localIndices);
- Map> inferenceFieldsMap = new HashMap<>(
+ Map> inferenceFieldsMap = new HashMap<>(
concreteLocalIndices.length
);
Arrays.stream(concreteLocalIndices).forEach(index -> {
- List inferenceFieldMetadataList = getInferenceFieldMetadata(
- index,
- fields,
- resolveWildcards,
- useDefaultFields
- );
+ List inferenceFieldMetadataList =
+ getInferenceFieldMetadata(index, fields, resolveWildcards, useDefaultFields);
inferenceFieldsMap.put(index, inferenceFieldMetadataList);
});
@@ -124,14 +120,14 @@ protected void doExecute(
getInferenceResults(query, inferenceIds, inferenceFieldsMap, listener);
} else {
- listener.onResponse(new GetInferenceFieldsAction.Response(inferenceFieldsMap, Map.of()));
+ listener.onResponse(new GetInferenceFieldsInternalAction.Response(inferenceFieldsMap, Map.of()));
}
} catch (Exception e) {
listener.onFailure(e);
}
}
- private List getInferenceFieldMetadata(
+ private List getInferenceFieldMetadata(
String index,
Map fields,
boolean resolveWildcards,
@@ -149,18 +145,18 @@ private List getInferen
);
return matchingInferenceFieldMap.entrySet()
.stream()
- .map(e -> new GetInferenceFieldsAction.ExtendedInferenceFieldMetadata(e.getKey(), e.getValue()))
+ .map(e -> new GetInferenceFieldsInternalAction.ExtendedInferenceFieldMetadata(e.getKey(), e.getValue()))
.toList();
}
private void getInferenceResults(
String query,
Set inferenceIds,
- Map> inferenceFieldsMap,
- ActionListener listener
+ Map> inferenceFieldsMap,
+ ActionListener listener
) {
if (inferenceIds.isEmpty()) {
- listener.onResponse(new GetInferenceFieldsAction.Response(inferenceFieldsMap, Map.of()));
+ listener.onResponse(new GetInferenceFieldsInternalAction.Response(inferenceFieldsMap, Map.of()));
return;
}
@@ -170,7 +166,10 @@ private void getInferenceResults(
Map inferenceResultsMap = new HashMap<>(inferenceIds.size());
c.forEach(t -> inferenceResultsMap.put(t.v1(), t.v2()));
- GetInferenceFieldsAction.Response response = new GetInferenceFieldsAction.Response(inferenceFieldsMap, inferenceResultsMap);
+ GetInferenceFieldsInternalAction.Response response = new GetInferenceFieldsInternalAction.Response(
+ inferenceFieldsMap,
+ inferenceResultsMap
+ );
l.onResponse(response);
})
);
diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/InferenceQueryUtils.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/InferenceQueryUtils.java
index a6fbc708911b0..61ab6e4423c3a 100644
--- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/InferenceQueryUtils.java
+++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/InferenceQueryUtils.java
@@ -33,7 +33,7 @@
import org.elasticsearch.inference.InferenceServiceResults;
import org.elasticsearch.inference.InputType;
import org.elasticsearch.inference.TaskType;
-import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction;
+import org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction;
import org.elasticsearch.xpack.core.inference.action.InferenceAction;
import org.elasticsearch.xpack.core.ml.action.CoordinatedInferenceAction;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelPrefixStrings;
@@ -56,7 +56,7 @@
import static org.elasticsearch.index.IndexSettings.DEFAULT_FIELD_SETTING;
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
-import static org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsAction.GET_INFERENCE_FIELDS_ACTION_TV;
+import static org.elasticsearch.xpack.core.inference.action.GetInferenceFieldsInternalAction.GET_INFERENCE_FIELDS_ACTION_AS_INDICES_ACTION_TV;
public final class InferenceQueryUtils {
/**
@@ -163,7 +163,8 @@ public static void getInferenceInfo(
}
SetOnce localInferenceInfoSupplier = new SetOnce<>();
- SetOnce