Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ protected final MapperService createMapperService(Settings settings, String mapp
protected final MapperService createMapperService(IndexVersion indexVersion, Settings settings, XContentBuilder mappings)
throws IOException {
MapperService mapperService = createMapperService(indexVersion, settings, () -> true, mappings);
merge(mapperService, mappings);
return mapperService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@
import java.util.Collections;

public class SemanticInferenceMetadataFieldsMapperTests extends MapperServiceTestCase {

static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
return getRandomCompatibleIndexVersion(useLegacyFormat, IndexVersion.current());
}

static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat, IndexVersion maxVersion) {
if (useLegacyFormat) {
if (randomBoolean()) {
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, maxVersion);
}
return IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT);
} else {
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, maxVersion);
}
}

@Override
protected Collection<? extends Plugin> getPlugins() {
return Collections.singletonList(new InferencePlugin(Settings.EMPTY));
Expand All @@ -61,4 +45,19 @@ public void testFieldHasValueWithEmptyFieldInfos() {
public MappedFieldType getMappedFieldType() {
return new SemanticInferenceMetadataFieldsMapper.FieldType();
}

static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
if (useLegacyFormat) {
// Randomly choose an index version compatible with the legacy semantic text format
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.SEMANTIC_TEXT_FIELD_TYPE, IndexVersion.current());
} else {
// Randomly choose an index version compatible with the new semantic text format
return IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT,
IndexVersion.current()
);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,35 +153,27 @@ protected Supplier<ModelRegistry> getModelRegistry() {

private MapperService createMapperService(XContentBuilder mappings, boolean useLegacyFormat) throws IOException {
IndexVersion indexVersion = SemanticInferenceMetadataFieldsMapperTests.getRandomCompatibleIndexVersion(useLegacyFormat);
return createMapperService(mappings, useLegacyFormat, indexVersion, indexVersion, false);
return createMapperService(mappings, useLegacyFormat, indexVersion, indexVersion);
}

private MapperService createMapperService(XContentBuilder mappings, boolean useLegacyFormat, IndexVersion minIndexVersion)
throws IOException {
return createMapperService(mappings, useLegacyFormat, minIndexVersion, IndexVersion.current(), false);
return createMapperService(mappings, useLegacyFormat, minIndexVersion, IndexVersion.current());
}

private MapperService createMapperService(
XContentBuilder mappings,
boolean useLegacyFormat,
IndexVersion minIndexVersion,
IndexVersion maxIndexVersion,
boolean propagateIndexVersion
IndexVersion maxIndexVersion
) throws IOException {
validateIndexVersion(minIndexVersion, useLegacyFormat);
IndexVersion indexVersion = IndexVersionUtils.randomVersionBetween(random(), minIndexVersion, maxIndexVersion);
var settings = Settings.builder()
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), indexVersion)
.put(InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT.getKey(), useLegacyFormat)
.build();
// TODO - This is added, because we discovered a bug where the index version was not being correctly propagated
// in our mappings even though we were specifying the index version in settings. We will fix this in a followup and
// remove the boolean flag accordingly.
if (propagateIndexVersion) {
return createMapperService(indexVersion, settings, mappings);
} else {
return createMapperService(settings, mappings);
}
return createMapperService(indexVersion, settings, mappings);
}

private static void validateIndexVersion(IndexVersion indexVersion, boolean useLegacyFormat) {
Expand Down Expand Up @@ -1187,8 +1179,7 @@ public void testDefaultIndexOptions() throws IOException {
}),
useLegacyFormat,
IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT,
IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X),
true
IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X)
);
assertSemanticTextField(mapperService, "field", true, null, defaultDenseVectorIndexOptions());

Expand Down