Skip to content

Commit d19ed5d

Browse files
committed
Revert "refactor(semantic_text): fail early in pre-8.11 indices (elastic#133080)"
This reverts commit 8f41a4b.
1 parent a399e29 commit d19ed5d

File tree

3 files changed

+1
-59
lines changed

3 files changed

+1
-59
lines changed

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import static org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase.randomNormalizedVector;
6868
import static org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat.DYNAMIC_VISIT_RATIO;
6969
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.DEFAULT_OVERSAMPLE;
70-
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.INDEXED_BY_DEFAULT_INDEX_VERSION;
7170
import static org.hamcrest.Matchers.containsString;
7271
import static org.hamcrest.Matchers.equalTo;
7372
import static org.hamcrest.Matchers.instanceOf;
@@ -106,7 +105,7 @@ private void indexMapping(XContentBuilder b, IndexVersion indexVersion) throws I
106105
if (elementType != ElementType.FLOAT) {
107106
b.field("element_type", elementType.toString());
108107
}
109-
if (indexVersion.onOrAfter(INDEXED_BY_DEFAULT_INDEX_VERSION) || indexed) {
108+
if (indexVersion.onOrAfter(DenseVectorFieldMapper.INDEXED_BY_DEFAULT_INDEX_VERSION) || indexed) {
110109
// Serialize if it's new index version, or it was not the default for previous indices
111110
b.field("index", indexed);
112111
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
import java.util.function.Function;
101101
import java.util.function.Supplier;
102102

103-
import static org.elasticsearch.index.IndexVersions.NEW_SPARSE_VECTOR;
104103
import static org.elasticsearch.index.IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ;
105104
import static org.elasticsearch.index.IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X;
106105
import static org.elasticsearch.inference.TaskType.SPARSE_EMBEDDING;
@@ -127,7 +126,6 @@
127126
*/
128127
public class SemanticTextFieldMapper extends FieldMapper implements InferenceFieldMapper {
129128
private static final Logger logger = LogManager.getLogger(SemanticTextFieldMapper.class);
130-
public static final String UNSUPPORTED_INDEX_MESSAGE = "[semantic_text] is available on indices created with 8.11 or higher.";
131129
public static final NodeFeature SEMANTIC_TEXT_IN_OBJECT_FIELD_FIX = new NodeFeature("semantic_text.in_object_field_fix");
132130
public static final NodeFeature SEMANTIC_TEXT_SINGLE_FIELD_UPDATE_FIX = new NodeFeature("semantic_text.single_field_update_fix");
133131
public static final NodeFeature SEMANTIC_TEXT_DELETE_FIX = new NodeFeature("semantic_text.delete_fix");
@@ -166,9 +164,6 @@ public static final TypeParser parser(Supplier<ModelRegistry> modelRegistry) {
166164

167165
public static BiConsumer<String, MappingParserContext> validateParserContext(String type) {
168166
return (n, c) -> {
169-
if (c.getIndexSettings().getIndexVersionCreated().before(NEW_SPARSE_VECTOR)) {
170-
throw new UnsupportedOperationException(UNSUPPORTED_INDEX_MESSAGE);
171-
}
172167
if (InferenceMetadataFieldsMapper.isEnabled(c.getIndexSettings().getSettings()) == false) {
173168
notInMultiFields(type).accept(n, c);
174169
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID;
112112
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_RESCORE_OVERSAMPLE;
113113
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD;
114-
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.UNSUPPORTED_INDEX_MESSAGE;
115114
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings;
116115
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan;
117116
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText;
@@ -415,57 +414,6 @@ public void testInvalidTaskTypes() {
415414
}
416415
}
417416

418-
@Override
419-
protected IndexVersion boostNotAllowedIndexVersion() {
420-
return IndexVersions.NEW_SPARSE_VECTOR;
421-
}
422-
423-
public void testOldIndexSemanticTextDenseVectorRaisesError() throws IOException {
424-
final String fieldName = "field";
425-
final XContentBuilder fieldMapping = fieldMapping(b -> {
426-
b.field("type", "semantic_text");
427-
b.field(INFERENCE_ID_FIELD, "test_inference_id");
428-
b.startObject("model_settings");
429-
b.field("task_type", "text_embedding");
430-
b.field("dimensions", 384);
431-
b.field("similarity", "cosine");
432-
b.field("element_type", "float");
433-
b.endObject();
434-
});
435-
assertOldIndexUnsupported(fieldMapping);
436-
}
437-
438-
public void testOldIndexSemanticTextMinimalMappingRaisesError() throws IOException {
439-
final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping);
440-
assertOldIndexUnsupported(fieldMapping);
441-
}
442-
443-
public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException {
444-
final XContentBuilder fieldMapping = fieldMapping(b -> {
445-
b.field("type", "semantic_text");
446-
b.field("inference_id", "another_inference_id");
447-
b.startObject("model_settings");
448-
b.field("task_type", "sparse_embedding");
449-
b.endObject();
450-
});
451-
assertOldIndexUnsupported(fieldMapping);
452-
}
453-
454-
private void assertOldIndexUnsupported(XContentBuilder fieldMapping) {
455-
456-
MapperParsingException exception = assertThrows(
457-
MapperParsingException.class,
458-
() -> createMapperService(
459-
fieldMapping,
460-
true,
461-
IndexVersions.V_8_0_0,
462-
IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR)
463-
)
464-
);
465-
assertTrue(exception.getMessage().contains(UNSUPPORTED_INDEX_MESSAGE));
466-
assertTrue(exception.getRootCause() instanceof UnsupportedOperationException);
467-
}
468-
469417
public void testMultiFieldsSupport() throws IOException {
470418
if (useLegacyFormat) {
471419
Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {

0 commit comments

Comments
 (0)