Put data frame analytics jobs API
editPut data frame analytics jobs API
editCreates a new data frame analytics job.
The API accepts a PutDataFrameAnalyticsRequest
object as a request and returns a PutDataFrameAnalyticsResponse
.
Put data frame analytics jobs request
editA PutDataFrameAnalyticsRequest
requires the following argument:
Data frame analytics configuration
editThe DataFrameAnalyticsConfig
object contains all the details about the
data frame analytics job configuration and contains the following arguments:
SourceConfig
editThe index and the query from which to collect data.
DataFrameAnalyticsSource sourceConfig = DataFrameAnalyticsSource.builder() .setIndex("put-test-source-index") .setQueryConfig(queryConfig) .build();
Constructing a new DataFrameAnalyticsSource |
|
The source index |
|
The query from which to gather the data. If query is not set, a |
QueryConfig
editThe query with which to select data from the source.
QueryConfig queryConfig = new QueryConfig(new MatchAllQueryBuilder());
DestinationConfig
editThe index to which data should be written by the data frame analytics job.
Analysis
editThe analysis to be performed.
Currently, only one analysis is supported: OutlierDetection
.
OutlierDetection
analysis can be created in one of two ways:
or
Analyzed fields
editFetchContext object containing fields to be included in / excluded from the analysis
FetchSourceContext analyzedFields = new FetchSourceContext( true, new String[] { "included_field_1", "included_field_2" }, new String[] { "excluded_field" });
Synchronous execution
editWhen executing a PutDataFrameAnalyticsRequest
in the following manner, the client waits
for the PutDataFrameAnalyticsResponse
to be returned before continuing with code execution:
PutDataFrameAnalyticsResponse response = client.machineLearning().putDataFrameAnalytics(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
editExecuting a PutDataFrameAnalyticsRequest
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 put-data-frame-analytics method:
The |
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 put-data-frame-analytics
looks like:
Response
editThe returned PutDataFrameAnalyticsResponse
contains the newly created data frame analytics job.
DataFrameAnalyticsConfig createdConfig = response.getConfig();