|
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;
|
| 97 | +import static org.hamcrest.Matchers.anyOf; |
96 | 98 | import static org.hamcrest.Matchers.containsString;
|
97 | 99 | import static org.hamcrest.Matchers.equalTo;
|
98 | 100 | import static org.hamcrest.Matchers.instanceOf;
|
@@ -337,6 +339,57 @@ public void testInvalidTaskTypes() {
|
337 | 339 | }
|
338 | 340 | }
|
339 | 341 |
|
| 342 | + @Override |
| 343 | + protected IndexVersion boostNotAllowedIndexVersion() { |
| 344 | + return IndexVersions.NEW_SPARSE_VECTOR; |
| 345 | + } |
| 346 | + |
| 347 | + public void testOldIndexSemanticTextDenseVectorRaisesError() throws IOException { |
| 348 | + final String fieldName = "field"; |
| 349 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 350 | + b.field("type", "semantic_text"); |
| 351 | + b.field(INFERENCE_ID_FIELD, "test_inference_id"); |
| 352 | + b.startObject("model_settings"); |
| 353 | + b.field("task_type", "text_embedding"); |
| 354 | + b.field("dimensions", 384); |
| 355 | + b.field("similarity", "cosine"); |
| 356 | + b.field("element_type", "float"); |
| 357 | + b.endObject(); |
| 358 | + }); |
| 359 | + assertOldIndexUnsupported(fieldMapping); |
| 360 | + } |
| 361 | + |
| 362 | + public void testOldIndexSemanticTextMinimalMappingRaisesError() throws IOException { |
| 363 | + final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping); |
| 364 | + assertOldIndexUnsupported(fieldMapping); |
| 365 | + } |
| 366 | + |
| 367 | + public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException { |
| 368 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 369 | + b.field("type", "semantic_text"); |
| 370 | + b.field("inference_id", "another_inference_id"); |
| 371 | + b.startObject("model_settings"); |
| 372 | + b.field("task_type", "sparse_embedding"); |
| 373 | + b.endObject(); |
| 374 | + }); |
| 375 | + assertOldIndexUnsupported(fieldMapping); |
| 376 | + } |
| 377 | + |
| 378 | + private void assertOldIndexUnsupported(XContentBuilder fieldMapping) { |
| 379 | + |
| 380 | + MapperParsingException exception = assertThrows( |
| 381 | + MapperParsingException.class, |
| 382 | + () -> createMapperService( |
| 383 | + fieldMapping, |
| 384 | + true, |
| 385 | + IndexVersions.V_8_0_0, |
| 386 | + IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR) |
| 387 | + ) |
| 388 | + ); |
| 389 | + assertTrue(exception.getMessage().contains(UNSUPPORTED_INDEX_MESSAGE)); |
| 390 | + assertTrue(exception.getRootCause() instanceof UnsupportedOperationException); |
| 391 | + } |
| 392 | + |
340 | 393 | public void testMultiFieldsSupport() throws IOException {
|
341 | 394 | if (useLegacyFormat) {
|
342 | 395 | Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {
|
@@ -973,6 +1026,34 @@ public void testExistsQueryDenseVector() throws IOException {
|
973 | 1026 | assertThat(existsQuery, instanceOf(ESToParentBlockJoinQuery.class));
|
974 | 1027 | }
|
975 | 1028 |
|
| 1029 | + /** |
| 1030 | + * Semantic text version error supersedes deprecated boost warning |
| 1031 | + * @throws IOException |
| 1032 | + */ |
| 1033 | + @Override |
| 1034 | + public void testDeprecatedBoostWarning() throws IOException { |
| 1035 | + try { |
| 1036 | + createMapperService(DEPRECATED_BOOST_INDEX_VERSION, fieldMapping(b -> { |
| 1037 | + minimalMapping(b, DEPRECATED_BOOST_INDEX_VERSION); |
| 1038 | + b.field("boost", 2.0); |
| 1039 | + })); |
| 1040 | + String[] warnings = Strings.concatStringArrays( |
| 1041 | + getParseMinimalWarnings(DEPRECATED_BOOST_INDEX_VERSION), |
| 1042 | + new String[] { "Parameter [boost] on field [field] is deprecated and has no effect" } |
| 1043 | + ); |
| 1044 | + assertWarnings(warnings); |
| 1045 | + } catch (MapperParsingException e) { |
| 1046 | + assertThat( |
| 1047 | + e.getMessage(), |
| 1048 | + anyOf( |
| 1049 | + containsString(UNSUPPORTED_INDEX_MESSAGE), |
| 1050 | + containsString("Unknown parameter [boost]"), |
| 1051 | + containsString("[boost : 2.0]") |
| 1052 | + ) |
| 1053 | + ); |
| 1054 | + } |
| 1055 | + } |
| 1056 | + |
976 | 1057 | @Override
|
977 | 1058 | protected void assertExistsQuery(MappedFieldType fieldType, Query query, LuceneDocument fields) {
|
978 | 1059 | // Until a doc is indexed, the query is rewritten as match no docs
|
|
0 commit comments