Stop Datafeed API

The Stop Datafeed API provides the ability to stop a machine learning datafeed in the cluster. It accepts a StopDatafeedRequest object and responds with a StopDatafeedResponse object.

Stop Datafeed Request

A StopDatafeedRequest object is created referencing any number of non-null datafeedId entries. Wildcards and _all are also accepted. All other fields are optional for the request.

StopDatafeedRequest request = new StopDatafeedRequest("datafeed_id1", "datafeed_id*"); 

Constructing a new request referencing existing datafeedId entries.

Optional Arguments

The following arguments are optional.

request.setAllowNoDatafeeds(true); 
request.setForce(true); 
request.setTimeout(TimeValue.timeValueMinutes(10)); 

Whether to ignore if a wildcard expression matches no datafeeds. (This includes _all string)

If true, the datafeed is stopped forcefully.

Controls the amount of time to wait until a datafeed stops. The default value is 20 seconds.

Synchronous Execution

When executing a StopDatafeedRequest in the following manner, the client waits for the StopDatafeedResponse to be returned before continuing with code execution:

StopDatafeedResponse response = client.machineLearning().stopDatafeed(request, RequestOptions.DEFAULT);

Synchronous calls may throw an IOException in case of either failing to parse the REST response in the high-level REST client, the request times out or similar cases where there is no response coming back from the server.

In cases where the server returns a 4xx or 5xx error code, the high-level client tries to parse the response body error details instead and then throws a generic ElasticsearchException and adds the original ResponseException as a suppressed exception to it.

Asynchronous Execution

Executing a StopDatafeedRequest can also be done in an asynchronous fashion so that the client can return directly. Users need to specify how the response or potential failures will be handled by passing the request and a listener to the asynchronous stop-datafeed method:

client.machineLearning().stopDatafeedAsync(request, RequestOptions.DEFAULT, listener); 

The StopDatafeedRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed. Failure scenarios and expected exceptions are the same as in the synchronous execution case.

A typical listener for stop-datafeed looks like:

ActionListener<StopDatafeedResponse> listener = new ActionListener<StopDatafeedResponse>() {
    @Override
    public void onResponse(StopDatafeedResponse response) {
        
    }

    @Override
    public void onFailure(Exception e) {
        
    }
};

Called when the execution is successfully completed.

Called when the whole StopDatafeedRequest fails.