diff --git a/server/src/main/java/org/opensearch/action/main/MainResponse.java b/server/src/main/java/org/opensearch/action/main/MainResponse.java index 467f33c1c3b..c1c0a71b243 100644 --- a/server/src/main/java/org/opensearch/action/main/MainResponse.java +++ b/server/src/main/java/org/opensearch/action/main/MainResponse.java @@ -139,9 +139,11 @@ public class MainResponse extends ActionResponse implements ToXContentObject { builder.field("name", nodeName); builder.field("cluster_name", clusterName.value()); builder.field("cluster_uuid", clusterUuid); - builder.startObject("version") - .field("distribution", build.getDistribution()) - .field("number", versionNumber) + builder.startObject("version"); + if (isCompatibilityModeDisabled()) { + builder.field("distribution", build.getDistribution()); + } + builder.field("number", versionNumber) .field("build_type", build.type().displayName()) .field("build_hash", build.hash()) .field("build_date", build.date()) @@ -155,6 +157,12 @@ public class MainResponse extends ActionResponse implements ToXContentObject { return builder; } + private boolean isCompatibilityModeDisabled() { + // if we are not in compatibility mode (spoofing versionNumber), then + // build.getQualifiedVersion is always used. + return build.getQualifiedVersion().equals(versionNumber); + } + private static final ObjectParser PARSER = new ObjectParser<>(MainResponse.class.getName(), true, MainResponse::new); diff --git a/server/src/test/java/org/opensearch/action/main/MainResponseTests.java b/server/src/test/java/org/opensearch/action/main/MainResponseTests.java index 550cf43799d..aa62a3880f4 100644 --- a/server/src/test/java/org/opensearch/action/main/MainResponseTests.java +++ b/server/src/test/java/org/opensearch/action/main/MainResponseTests.java @@ -112,6 +112,7 @@ public class MainResponseTests extends AbstractSerializingTestCase XContentBuilder builder = XContentFactory.jsonBuilder(); response.toXContent(builder, ToXContent.EMPTY_PARAMS); assertTrue(Strings.toString(builder).contains("\"number\":\"" + responseVersion + "\",")); + assertFalse(Strings.toString(builder).contains("\"distribution\":\"" + Build.CURRENT.getDistribution() + "\",")); } @Override