|
92 | 92 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.getChunksFieldName; |
93 | 93 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.getEmbeddingsFieldName; |
94 | 94 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID; |
| 95 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.UNSUPPORTED_INDEX_MESSAGE; |
95 | 96 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText; |
96 | 97 | import static org.hamcrest.Matchers.containsString; |
97 | 98 | import static org.hamcrest.Matchers.equalTo; |
@@ -339,6 +340,57 @@ public void testInvalidTaskTypes() { |
339 | 340 | } |
340 | 341 | } |
341 | 342 |
|
| 343 | + @Override |
| 344 | + protected IndexVersion boostNotAllowedIndexVersion() { |
| 345 | + return IndexVersions.NEW_SPARSE_VECTOR; |
| 346 | + } |
| 347 | + |
| 348 | + public void testOldIndexSemanticTextDenseVectorRaisesError() throws IOException { |
| 349 | + final String fieldName = "field"; |
| 350 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 351 | + b.field("type", "semantic_text"); |
| 352 | + b.field(INFERENCE_ID_FIELD, "test_inference_id"); |
| 353 | + b.startObject("model_settings"); |
| 354 | + b.field("task_type", "text_embedding"); |
| 355 | + b.field("dimensions", 384); |
| 356 | + b.field("similarity", "cosine"); |
| 357 | + b.field("element_type", "float"); |
| 358 | + b.endObject(); |
| 359 | + }); |
| 360 | + assertOldIndexUnsupported(fieldMapping); |
| 361 | + } |
| 362 | + |
| 363 | + public void testOldIndexSemanticTextMinimalMappingRaisesError() throws IOException { |
| 364 | + final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping); |
| 365 | + assertOldIndexUnsupported(fieldMapping); |
| 366 | + } |
| 367 | + |
| 368 | + public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException { |
| 369 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 370 | + b.field("type", "semantic_text"); |
| 371 | + b.field("inference_id", "another_inference_id"); |
| 372 | + b.startObject("model_settings"); |
| 373 | + b.field("task_type", "sparse_embedding"); |
| 374 | + b.endObject(); |
| 375 | + }); |
| 376 | + assertOldIndexUnsupported(fieldMapping); |
| 377 | + } |
| 378 | + |
| 379 | + private void assertOldIndexUnsupported(XContentBuilder fieldMapping) { |
| 380 | + |
| 381 | + MapperParsingException exception = assertThrows( |
| 382 | + MapperParsingException.class, |
| 383 | + () -> createMapperService( |
| 384 | + fieldMapping, |
| 385 | + true, |
| 386 | + IndexVersions.V_8_0_0, |
| 387 | + IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR) |
| 388 | + ) |
| 389 | + ); |
| 390 | + assertTrue(exception.getMessage().contains(UNSUPPORTED_INDEX_MESSAGE)); |
| 391 | + assertTrue(exception.getRootCause() instanceof UnsupportedOperationException); |
| 392 | + } |
| 393 | + |
342 | 394 | public void testMultiFieldsSupport() throws IOException { |
343 | 395 | if (useLegacyFormat) { |
344 | 396 | Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> { |
|
0 commit comments