Skip to content

Commit 7f11346

Browse files
author
Max Hniebergall
committed
Add mappings for endpoint_version
1 parent 714535e commit 7f11346

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferenceIndex.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.cluster.metadata.IndexMetadata;
1111
import org.elasticsearch.common.settings.Settings;
1212
import org.elasticsearch.indices.SystemIndexDescriptor;
13+
import org.elasticsearch.inference.ModelConfigurations;
1314
import org.elasticsearch.xcontent.XContentBuilder;
1415

1516
import java.io.IOException;
@@ -27,7 +28,7 @@ private InferenceIndex() {}
2728
public static final String INDEX_ALIAS = ".inference-alias";
2829

2930
// Increment this version number when the mappings change
30-
private static final int INDEX_MAPPING_VERSION = 2;
31+
private static final int INDEX_MAPPING_VERSION = 3;
3132

3233
public static Settings settings() {
3334
return Settings.builder()
@@ -58,6 +59,56 @@ public static Settings settings() {
5859
* @return The index mappings
5960
*/
6061
public static XContentBuilder mappings() {
62+
try {
63+
var jsonBuilder = jsonBuilder().startObject().startObject(SINGLE_MAPPING_NAME);
64+
{
65+
jsonBuilder.startObject("_meta").field(SystemIndexDescriptor.VERSION_META_KEY, INDEX_MAPPING_VERSION).endObject();
66+
67+
jsonBuilder.field("dynamic", "strict");
68+
69+
jsonBuilder.startObject("properties");
70+
{
71+
jsonBuilder.startObject("model_id").field("type", "keyword").endObject();
72+
73+
jsonBuilder.startObject("task_type").field("type", "keyword").endObject();
74+
75+
jsonBuilder.startObject("service").field("type", "keyword").endObject();
76+
77+
jsonBuilder.startObject("service_settings").field("dynamic", "false");
78+
{
79+
jsonBuilder.startObject("properties").endObject();
80+
}
81+
jsonBuilder.endObject();
82+
83+
jsonBuilder.startObject("task_settings").field("dynamic", "false");
84+
{
85+
jsonBuilder.startObject("properties").endObject();
86+
}
87+
jsonBuilder.endObject();
88+
89+
jsonBuilder.startObject("chunking_settings");
90+
{
91+
jsonBuilder.field("dynamic", "false");
92+
jsonBuilder.startObject("properties");
93+
{
94+
jsonBuilder.startObject("strategy").field("type", "keyword").endObject();
95+
}
96+
jsonBuilder.endObject();
97+
}
98+
jsonBuilder.endObject();
99+
100+
jsonBuilder.startObject("endpoint_version").field("dynamic", "false").field("type", "keyword").endObject();
101+
}
102+
jsonBuilder.endObject().endObject().endObject();
103+
}
104+
105+
return jsonBuilder;
106+
} catch (IOException e) {
107+
throw new UncheckedIOException("Failed to build mappings for index " + INDEX_NAME, e);
108+
}
109+
}
110+
111+
public static XContentBuilder mappingsV2() {
61112
try {
62113
return jsonBuilder().startObject()
63114
.startObject(SINGLE_MAPPING_NAME)

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
259259
@Override
260260
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
261261

262+
var inferenceIndexV2Descriptor = SystemIndexDescriptor.builder()
263+
.setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED)
264+
.setIndexPattern(InferenceIndex.INDEX_PATTERN)
265+
.setAliasName(InferenceIndex.INDEX_ALIAS)
266+
.setPrimaryIndex(InferenceIndex.INDEX_NAME)
267+
.setDescription("Contains inference service and model configuration")
268+
.setMappings(InferenceIndex.mappingsV2())
269+
.setSettings(InferenceIndex.settings())
270+
.setVersionMetaKey("version")
271+
.setOrigin(ClientHelper.INFERENCE_ORIGIN)
272+
.build();
273+
262274
var inferenceIndexV1Descriptor = SystemIndexDescriptor.builder()
263275
.setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED)
264276
.setIndexPattern(InferenceIndex.INDEX_PATTERN)
@@ -282,7 +294,7 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
282294
.setSettings(InferenceIndex.settings())
283295
.setVersionMetaKey("version")
284296
.setOrigin(ClientHelper.INFERENCE_ORIGIN)
285-
.setPriorSystemIndexDescriptors(List.of(inferenceIndexV1Descriptor))
297+
.setPriorSystemIndexDescriptors(List.of(inferenceIndexV1Descriptor, inferenceIndexV2Descriptor))
286298
.build(),
287299
SystemIndexDescriptor.builder()
288300
.setType(SystemIndexDescriptor.Type.INTERNAL_MANAGED)

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportPutInferenceModelAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,15 @@ private void parseAndStoreModel(
177177
new ElasticsearchStatusException(
178178
"One or more nodes in your cluster does not support chunking_settings. "
179179
+ "Please update all nodes in your cluster to the latest version to use chunking_settings.",
180-
RestStatus.BAD_REQUEST
180+
RestStatus.CONFLICT
181+
)
182+
);
183+
} else if (e.getCause() instanceof StrictDynamicMappingException) {
184+
delegate.onFailure(
185+
new ElasticsearchStatusException(
186+
"One or more nodes in your cluster is not on the latest version "
187+
+ "Please update all nodes in your cluster to the latest version to put inference endpoints.",
188+
RestStatus.CONFLICT
181189
)
182190
);
183191
} else {

0 commit comments

Comments
 (0)