Skip to content

Commit 65a3d02

Browse files
committed
Better fix for null inputs
1 parent 062eeac commit 65a3d02

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,13 @@ protected void merge(FieldMapper mergeWith, Conflicts conflicts, MapperMergeCont
293293
SemanticTextFieldMapper semanticMergeWith = (SemanticTextFieldMapper) mergeWith;
294294
semanticMergeWith = copySettings(semanticMergeWith, mapperMergeContext);
295295

296-
super.merge(semanticMergeWith, conflicts, mapperMergeContext);
297-
conflicts.check();
298296
var context = mapperMergeContext.createChildContext(semanticMergeWith.leafName(), ObjectMapper.Dynamic.FALSE);
299297
var inferenceField = inferenceFieldBuilder.apply(context.getMapperBuilderContext());
300298
var mergedInferenceField = inferenceField.merge(semanticMergeWith.fieldType().getInferenceField(), context);
301299
inferenceFieldBuilder = c -> mergedInferenceField;
300+
301+
super.merge(semanticMergeWith, conflicts, mapperMergeContext);
302+
conflicts.check();
302303
}
303304

304305
/**
@@ -1218,11 +1219,10 @@ static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDenseVectorI
12181219
return new DenseVectorFieldMapper.BBQHnswIndexOptions(m, efConstruction, rescoreVector);
12191220
}
12201221

1221-
static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions(IndexVersion indexVersion) {
1222+
static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions() {
12221223
return new SemanticTextIndexOptions(
12231224
SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR,
1224-
defaultBbqHnswDenseVectorIndexOptions(),
1225-
indexVersion
1225+
defaultBbqHnswDenseVectorIndexOptions()
12261226
);
12271227
}
12281228

@@ -1242,15 +1242,9 @@ private static boolean canMergeIndexOptions(SemanticTextIndexOptions previous, S
12421242
return true;
12431243
}
12441244

1245-
if (previous == null
1246-
&& current.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR
1247-
&& indexVersionDefaultsToBbqHnsw(current.indexVersion())) {
1248-
return canMergeIndexOptions(defaultBbqHnswSemanticTextIndexOptions(current.indexVersion()), current, conflicts);
1249-
} else if (current == null
1250-
&& previous.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR
1251-
&& indexVersionDefaultsToBbqHnsw(previous.indexVersion())) {
1252-
return canMergeIndexOptions(previous, defaultBbqHnswSemanticTextIndexOptions(previous.indexVersion()), conflicts);
1253-
}
1245+
if (previous == null || current == null) {
1246+
return true;
1247+
}
12541248

12551249
if (previous.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR) {
12561250
DenseVectorFieldMapper.DenseVectorIndexOptions previousDenseOptions = (DenseVectorFieldMapper.DenseVectorIndexOptions) previous
@@ -1283,10 +1277,6 @@ private static SemanticTextIndexOptions parseIndexOptionsFromMap(String fieldNam
12831277
);
12841278
@SuppressWarnings("unchecked")
12851279
Map<String, Object> indexOptionsMap = (Map<String, Object>) entry.getValue();
1286-
return new SemanticTextIndexOptions(
1287-
indexOptions,
1288-
indexOptions.parseIndexOptions(fieldName, indexOptionsMap, indexVersion),
1289-
indexVersion
1290-
);
1280+
return new SemanticTextIndexOptions(indexOptions, indexOptions.parseIndexOptions(fieldName, indexOptionsMap, indexVersion));
12911281
}
12921282
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ public class SemanticTextIndexOptions implements ToXContent {
3636

3737
private final SupportedIndexOptions type;
3838
private final IndexOptions indexOptions;
39-
private final IndexVersion indexVersion;
4039

41-
public SemanticTextIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions, IndexVersion indexVersion) {
40+
public SemanticTextIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions) {
4241
this.type = type;
4342
this.indexOptions = indexOptions;
44-
this.indexVersion = indexVersion;
4543
}
4644

4745
public SupportedIndexOptions type() {
@@ -52,10 +50,6 @@ public IndexOptions indexOptions() {
5250
return indexOptions;
5351
}
5452

55-
public IndexVersion indexVersion() {
56-
return indexVersion;
57-
}
58-
5953
public enum SupportedIndexOptions {
6054
DENSE_VECTOR("dense_vector") {
6155
@Override

0 commit comments

Comments
 (0)