@@ -37,7 +37,10 @@ public void testIsEnabled() {
37
37
assertFalse (InferenceMetadataFieldsMapper .isEnabled (settings ));
38
38
39
39
settings = Settings .builder ()
40
- .put (IndexMetadata .SETTING_INDEX_VERSION_CREATED .getKey (), getRandomCompatibleIndexVersion (true ))
40
+ .put (
41
+ IndexMetadata .SETTING_INDEX_VERSION_CREATED .getKey (),
42
+ getRandomCompatibleIndexVersion (true , IndexVersionUtils .getPreviousVersion (IndexVersions .INFERENCE_METADATA_FIELDS ))
43
+ )
41
44
.put (InferenceMetadataFieldsMapper .USE_LEGACY_SEMANTIC_TEXT_FORMAT .getKey (), false )
42
45
.build ();
43
46
assertFalse (InferenceMetadataFieldsMapper .isEnabled (settings ));
@@ -114,14 +117,18 @@ public MappedFieldType getMappedFieldType() {
114
117
}
115
118
116
119
static IndexVersion getRandomCompatibleIndexVersion (boolean useLegacyFormat ) {
120
+ return getRandomCompatibleIndexVersion (useLegacyFormat , IndexVersion .current ());
121
+ }
122
+
123
+ static IndexVersion getRandomCompatibleIndexVersion (boolean useLegacyFormat , IndexVersion maxVersion ) {
117
124
if (useLegacyFormat ) {
118
125
if (randomBoolean ()) {
119
- return IndexVersionUtils .randomVersionBetween (random (), IndexVersions .UPGRADE_TO_LUCENE_10_0_0 , IndexVersion . current () );
126
+ return IndexVersionUtils .randomVersionBetween (random (), IndexVersions .UPGRADE_TO_LUCENE_10_0_0 , maxVersion );
120
127
}
121
128
return IndexVersionUtils .randomPreviousCompatibleVersion (random (), IndexVersions .INFERENCE_METADATA_FIELDS_BACKPORT );
122
129
} else {
123
130
if (randomBoolean ()) {
124
- return IndexVersionUtils .randomVersionBetween (random (), IndexVersions .INFERENCE_METADATA_FIELDS , IndexVersion . current () );
131
+ return IndexVersionUtils .randomVersionBetween (random (), IndexVersions .INFERENCE_METADATA_FIELDS , maxVersion );
125
132
}
126
133
return IndexVersionUtils .randomVersionBetween (
127
134
random (),
@@ -130,4 +137,5 @@ static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
130
137
);
131
138
}
132
139
}
140
+
133
141
}
0 commit comments