|
9 | 9 |
|
10 | 10 | import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; |
11 | 11 |
|
| 12 | +import org.apache.logging.log4j.Level; |
12 | 13 | import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat; |
13 | 14 | import org.apache.lucene.document.FeatureField; |
14 | 15 | import org.apache.lucene.index.FieldInfo; |
|
27 | 28 | import org.apache.lucene.search.join.ScoreMode; |
28 | 29 | import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; |
29 | 30 | import org.elasticsearch.cluster.ClusterChangedEvent; |
| 31 | +import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention; |
| 32 | +import org.elasticsearch.cluster.metadata.DataStreamLifecycle; |
30 | 33 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
31 | 34 | import org.elasticsearch.common.CheckedBiConsumer; |
32 | 35 | import org.elasticsearch.common.CheckedBiFunction; |
33 | 36 | import org.elasticsearch.common.Strings; |
34 | 37 | import org.elasticsearch.common.bytes.BytesReference; |
35 | 38 | import org.elasticsearch.common.compress.CompressedXContent; |
| 39 | +import org.elasticsearch.common.logging.DeprecatedMessage; |
| 40 | +import org.elasticsearch.common.logging.DeprecationLogger; |
| 41 | +import org.elasticsearch.common.logging.ESLogMessage; |
| 42 | +import org.elasticsearch.common.logging.HeaderWarning; |
36 | 43 | import org.elasticsearch.common.lucene.search.Queries; |
37 | 44 | import org.elasticsearch.common.settings.Settings; |
| 45 | +import org.elasticsearch.common.util.concurrent.ThreadContext; |
38 | 46 | import org.elasticsearch.core.CheckedConsumer; |
| 47 | +import org.elasticsearch.core.TimeValue; |
39 | 48 | import org.elasticsearch.index.IndexVersion; |
40 | 49 | import org.elasticsearch.index.IndexVersions; |
41 | 50 | import org.elasticsearch.index.mapper.DocumentMapper; |
|
110 | 119 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.getEmbeddingsFieldName; |
111 | 120 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID; |
112 | 121 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_RESCORE_OVERSAMPLE; |
| 122 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.ERROR_MESSAGE_UNSUPPORTED_SPARSE_VECTOR; |
113 | 123 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD; |
| 124 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.WARNING_MESSAGE_8X; |
114 | 125 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings; |
115 | 126 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan; |
116 | 127 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText; |
@@ -414,6 +425,53 @@ public void testInvalidTaskTypes() { |
414 | 425 | } |
415 | 426 | } |
416 | 427 |
|
| 428 | + @Override |
| 429 | + protected String[] getParseMinimalWarnings() { |
| 430 | + return new String[] { |
| 431 | + WARNING_MESSAGE_8X |
| 432 | + }; |
| 433 | + } |
| 434 | + |
| 435 | + public void testOldIndexSemanticTextDenseVectorCreation() throws IOException { |
| 436 | + final String fieldName = "field"; |
| 437 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 438 | + b.field("type", "semantic_text"); |
| 439 | + b.field(INFERENCE_ID_FIELD, "test_inference_id"); |
| 440 | + b.startObject("model_settings"); |
| 441 | + b.field("task_type", "text_embedding"); |
| 442 | + b.field("dimensions", 384); |
| 443 | + b.field("similarity", "cosine"); |
| 444 | + b.field("element_type", "float"); |
| 445 | + b.endObject(); |
| 446 | + }); |
| 447 | + |
| 448 | + MapperService mapperService = createMapperService( |
| 449 | + fieldMapping, |
| 450 | + true, |
| 451 | + IndexVersions.V_8_0_0, |
| 452 | + IndexVersionUtils.getPreviousVersion(IndexVersions.FIRST_DETACHED_INDEX_VERSION)); |
| 453 | + assertParseMinimalWarnings(); |
| 454 | + assertSemanticTextField(mapperService, fieldName, true, null, null); |
| 455 | + } |
| 456 | + |
| 457 | + public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException { |
| 458 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 459 | + b.field("type", "semantic_text"); |
| 460 | + b.field("inference_id", "another_inference_id"); |
| 461 | + b.startObject("model_settings"); |
| 462 | + b.field("task_type", "sparse_embedding"); |
| 463 | + b.endObject(); |
| 464 | + }); |
| 465 | + |
| 466 | + MapperParsingException exception = assertThrows(MapperParsingException.class, () -> createMapperService( |
| 467 | + fieldMapping, |
| 468 | + true, |
| 469 | + IndexVersions.V_8_0_0, |
| 470 | + IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR))); |
| 471 | + assertTrue(exception.getMessage().contains(ERROR_MESSAGE_UNSUPPORTED_SPARSE_VECTOR)); |
| 472 | + assertTrue(exception.getRootCause() instanceof IllegalArgumentException); |
| 473 | + } |
| 474 | + |
417 | 475 | public void testMultiFieldsSupport() throws IOException { |
418 | 476 | if (useLegacyFormat) { |
419 | 477 | Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> { |
|
0 commit comments