|
107 | 107 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID;
|
108 | 108 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_RESCORE_OVERSAMPLE;
|
109 | 109 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD;
|
| 110 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.UNSUPPORTED_INDEX_MESSAGE; |
110 | 111 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings;
|
111 | 112 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan;
|
112 | 113 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText;
|
@@ -402,6 +403,57 @@ public void testInvalidTaskTypes() {
|
402 | 403 | }
|
403 | 404 | }
|
404 | 405 |
|
| 406 | + @Override |
| 407 | + protected IndexVersion boostNotAllowedIndexVersion() { |
| 408 | + return IndexVersions.NEW_SPARSE_VECTOR; |
| 409 | + } |
| 410 | + |
| 411 | + public void testOldIndexSemanticTextDenseVectorRaisesError() throws IOException { |
| 412 | + final String fieldName = "field"; |
| 413 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 414 | + b.field("type", "semantic_text"); |
| 415 | + b.field(INFERENCE_ID_FIELD, "test_inference_id"); |
| 416 | + b.startObject("model_settings"); |
| 417 | + b.field("task_type", "text_embedding"); |
| 418 | + b.field("dimensions", 384); |
| 419 | + b.field("similarity", "cosine"); |
| 420 | + b.field("element_type", "float"); |
| 421 | + b.endObject(); |
| 422 | + }); |
| 423 | + assertOldIndexUnsupported(fieldMapping); |
| 424 | + } |
| 425 | + |
| 426 | + public void testOldIndexSemanticTextMinimalMappingRaisesError() throws IOException { |
| 427 | + final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping); |
| 428 | + assertOldIndexUnsupported(fieldMapping); |
| 429 | + } |
| 430 | + |
| 431 | + public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException { |
| 432 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 433 | + b.field("type", "semantic_text"); |
| 434 | + b.field("inference_id", "another_inference_id"); |
| 435 | + b.startObject("model_settings"); |
| 436 | + b.field("task_type", "sparse_embedding"); |
| 437 | + b.endObject(); |
| 438 | + }); |
| 439 | + assertOldIndexUnsupported(fieldMapping); |
| 440 | + } |
| 441 | + |
| 442 | + private void assertOldIndexUnsupported(XContentBuilder fieldMapping) { |
| 443 | + |
| 444 | + MapperParsingException exception = assertThrows( |
| 445 | + MapperParsingException.class, |
| 446 | + () -> createMapperService( |
| 447 | + fieldMapping, |
| 448 | + true, |
| 449 | + IndexVersions.V_8_0_0, |
| 450 | + IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR) |
| 451 | + ) |
| 452 | + ); |
| 453 | + assertTrue(exception.getMessage().contains(UNSUPPORTED_INDEX_MESSAGE)); |
| 454 | + assertTrue(exception.getRootCause() instanceof UnsupportedOperationException); |
| 455 | + } |
| 456 | + |
405 | 457 | public void testMultiFieldsSupport() throws IOException {
|
406 | 458 | if (useLegacyFormat) {
|
407 | 459 | Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {
|
|
0 commit comments