From 55607376e477fae7c4cea934e7839a7431334fe0 Mon Sep 17 00:00:00 2001 From: Aurelien FOUCRET Date: Tue, 21 Nov 2023 12:02:52 +0100 Subject: [PATCH] Simplify LearnToRankRescorerBuilder serialization code. --- .../xpack/ml/ltr/LearnToRankRescorerBuilder.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/ltr/LearnToRankRescorerBuilder.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/ltr/LearnToRankRescorerBuilder.java index dfd96dbb27bbc..17b6882c46eb8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/ltr/LearnToRankRescorerBuilder.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/ltr/LearnToRankRescorerBuilder.java @@ -21,6 +21,7 @@ import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction; +import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfig; import org.elasticsearch.xpack.core.ml.inference.trainedmodel.LearnToRankConfig; import org.elasticsearch.xpack.ml.inference.loadingservice.LocalModel; @@ -89,11 +90,7 @@ public LearnToRankRescorerBuilder(StreamInput input, LearnToRankService learnToR super(input); this.modelId = input.readString(); this.params = input.readMap(); - if (input.readBoolean()) { - this.learnToRankConfig = new LearnToRankConfig(input); - } else { - this.learnToRankConfig = null; - } + this.learnToRankConfig = (LearnToRankConfig) input.readOptionalNamedWriteable(InferenceConfig.class); this.learnToRankService = learnToRankService; this.localModel = null; @@ -258,13 +255,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { assert localModel == null || rescoreOccurred : "Unnecessarily populated local model object"; out.writeString(modelId); out.writeGenericMap(params); - - if (learnToRankConfig != null) { - out.writeBoolean(true); - learnToRankConfig.writeTo(out); - } else { - out.writeBoolean(false); - } + out.writeOptionalNamedWriteable(learnToRankConfig); } @Override