Skip to content

Commit

Permalink
Fix serialization issues when inference is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Mar 14, 2024
1 parent a026612 commit f56db05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public FieldInferenceMetadata(Map<String, FieldInference> fieldsToInferenceMap)
fieldInferenceMap = ImmutableOpenMap.builder(fieldsToInferenceMap).build();
}

public boolean isEmpty() {
return fieldInferenceMap.isEmpty();
}

public record FieldInference(String inferenceId, Set<String> sourceFields)
implements
SimpleDiffable<FieldInference>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ private IndexMetadata(
this.writeLoadForecast = writeLoadForecast;
this.shardSizeInBytesForecast = shardSizeInBytesForecast;
assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards;
this.fieldInferenceMetadata = fieldInferenceMetadata;
this.fieldInferenceMetadata = Objects.requireNonNullElse(fieldInferenceMetadata, FieldInferenceMetadata.EMPTY);
}

IndexMetadata withMappingMetadata(MappingMetadata mapping) {
Expand Down Expand Up @@ -2422,7 +2422,9 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build
builder.field(KEY_SHARD_SIZE_FORECAST, indexMetadata.shardSizeInBytesForecast);
}

builder.field(KEY_FIELD_INFERENCE_METADATA, indexMetadata.fieldInferenceMetadata);
if (indexMetadata.fieldInferenceMetadata.isEmpty() == false) {
builder.field(KEY_FIELD_INFERENCE_METADATA, indexMetadata.fieldInferenceMetadata);
}

builder.endObject();
}
Expand Down

0 comments on commit f56db05

Please sign in to comment.