Skip to content

Commit 5ed27a7

Browse files
[ML] Reject data frame analytics using runtime fields if not all nodes support it (#69331)
When a data frame anylytics job config contains runtime mappings, when the task starts the destination index will be created with a `runtime` section in its mappings. If the cluster contains nodes that are on a version prior to the addition of runtime fields, the index creation will fail. Thus, this commit adds a check to prevent such jobs from being created and it informs the user on the preconditions for using runtime fields in data frame analytics.
1 parent c0a4076 commit 5ed27a7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDataFrameAnalyticsAction.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.license.License;
2828
import org.elasticsearch.license.LicenseUtils;
2929
import org.elasticsearch.license.XPackLicenseState;
30+
import org.elasticsearch.search.builder.SearchSourceBuilder;
3031
import org.elasticsearch.tasks.Task;
3132
import org.elasticsearch.threadpool.ThreadPool;
3233
import org.elasticsearch.transport.TransportService;
@@ -39,6 +40,7 @@
3940
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
4041
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
4142
import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings;
43+
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
4244
import org.elasticsearch.xpack.core.security.SecurityContext;
4345
import org.elasticsearch.xpack.core.security.action.user.HasPrivilegesAction;
4446
import org.elasticsearch.xpack.core.security.action.user.HasPrivilegesRequest;
@@ -115,6 +117,21 @@ protected void masterOperation(PutDataFrameAnalyticsAction.Request request, Clus
115117

116118
final DataFrameAnalyticsConfig config = request.getConfig();
117119

120+
// Check if runtime mappings are used but the cluster contains nodes on a version
121+
// before runtime fields were introduced and reject such configs.
122+
if (config.getSource().getRuntimeMappings().isEmpty() == false && state.nodes().getMinNodeVersion().before(Version.V_7_11_0)) {
123+
listener.onFailure(ExceptionsHelper.badRequestException(
124+
"at least one cluster node is on a version [{}] that does not support [{}]; " +
125+
"all nodes should be at least on version [{}] in order to create data frame analytics with [{}]",
126+
state.nodes().getMinNodeVersion(),
127+
SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD.getPreferredName(),
128+
Version.V_7_11_0,
129+
SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD.getPreferredName()
130+
)
131+
);
132+
return;
133+
}
134+
118135
ActionListener<Boolean> sourceDestValidationListener = ActionListener.wrap(
119136
aBoolean -> putValidatedConfig(config, listener),
120137
listener::onFailure

0 commit comments

Comments
 (0)