Stop Datafeed API

edit

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

edit

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

edit

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

edit

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);

Asynchronous Execution

edit

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.

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.