Skip to content

Commit

Permalink
HLRC: Add ML get influencers API (#33389)
Browse files Browse the repository at this point in the history
Relates #29827
  • Loading branch information
dimitris-athanasiou committed Sep 5, 2018
1 parent 71c0ee5 commit aff5658
Show file tree
Hide file tree
Showing 18 changed files with 864 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.GetBucketsRequest;
import org.elasticsearch.client.ml.GetInfluencersRequest;
import org.elasticsearch.client.ml.GetJobRequest;
import org.elasticsearch.client.ml.GetJobStatsRequest;
import org.elasticsearch.client.ml.GetOverallBucketsRequest;
Expand Down Expand Up @@ -186,4 +187,18 @@ static Request getRecords(GetRecordsRequest getRecordsRequest) throws IOExceptio
request.setEntity(createEntity(getRecordsRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getInfluencers(GetInfluencersRequest getInfluencersRequest) throws IOException {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("ml")
.addPathPartAsIs("anomaly_detectors")
.addPathPart(getInfluencersRequest.getJobId())
.addPathPartAsIs("results")
.addPathPartAsIs("influencers")
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
request.setEntity(createEntity(getInfluencersRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
package org.elasticsearch.client;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.FlushJobResponse;
import org.elasticsearch.client.ml.GetJobStatsRequest;
import org.elasticsearch.client.ml.GetJobStatsResponse;
import org.elasticsearch.client.ml.job.stats.JobStats;
import org.elasticsearch.client.ml.CloseJobRequest;
import org.elasticsearch.client.ml.CloseJobResponse;
import org.elasticsearch.client.ml.DeleteJobRequest;
import org.elasticsearch.client.ml.DeleteJobResponse;
import org.elasticsearch.client.ml.FlushJobRequest;
import org.elasticsearch.client.ml.FlushJobResponse;
import org.elasticsearch.client.ml.GetBucketsRequest;
import org.elasticsearch.client.ml.GetBucketsResponse;
import org.elasticsearch.client.ml.GetInfluencersRequest;
import org.elasticsearch.client.ml.GetInfluencersResponse;
import org.elasticsearch.client.ml.GetJobRequest;
import org.elasticsearch.client.ml.GetJobResponse;
import org.elasticsearch.client.ml.GetJobStatsRequest;
import org.elasticsearch.client.ml.GetJobStatsResponse;
import org.elasticsearch.client.ml.GetOverallBucketsRequest;
import org.elasticsearch.client.ml.GetOverallBucketsResponse;
import org.elasticsearch.client.ml.GetRecordsRequest;
Expand All @@ -40,6 +41,7 @@
import org.elasticsearch.client.ml.OpenJobResponse;
import org.elasticsearch.client.ml.PutJobRequest;
import org.elasticsearch.client.ml.PutJobResponse;
import org.elasticsearch.client.ml.job.stats.JobStats;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -464,4 +466,43 @@ public void getRecordsAsync(GetRecordsRequest request, RequestOptions options, A
listener,
Collections.emptySet());
}

/**
* Gets the influencers for a Machine Learning Job.
* <p>
* For additional info
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html">
* ML GET influencers documentation</a>
*
* @param request the request
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public GetInfluencersResponse getInfluencers(GetInfluencersRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::getInfluencers,
options,
GetInfluencersResponse::fromXContent,
Collections.emptySet());
}

/**
* Gets the influencers for a Machine Learning Job, notifies listener once the requested influencers are retrieved.
* <p>
* For additional info
* * see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html">
* ML GET influencers documentation</a>
*
* @param request the request
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener Listener to be notified upon request completion
*/
public void getInfluencersAsync(GetInfluencersRequest request, RequestOptions options,
ActionListener<GetInfluencersResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::getInfluencers,
options,
GetInfluencersResponse::fromXContent,
listener,
Collections.emptySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class GetBucketsRequest extends ActionRequest implements ToXContentObject
public static final ParseField START = new ParseField("start");
public static final ParseField END = new ParseField("end");
public static final ParseField ANOMALY_SCORE = new ParseField("anomaly_score");
public static final ParseField TIMESTAMP = new ParseField("timestamp");
public static final ParseField SORT = new ParseField("sort");
public static final ParseField DESCENDING = new ParseField("desc");

Expand Down Expand Up @@ -87,7 +86,7 @@ public String getJobId() {

/**
* Sets the timestamp of a specific bucket to be retrieved.
* @param timestamp the timestamp of a specific bucket to be retrieved
* @param timestamp String representation of a timestamp; may be an epoch seconds, epoch millis or an ISO string
*/
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
Expand All @@ -106,11 +105,11 @@ public boolean isExpand() {
* When {@code true}, buckets will be expanded to include their records.
* @param expand value of "expand" to be set
*/
public void setExpand(boolean expand) {
public void setExpand(Boolean expand) {
this.expand = expand;
}

public boolean isExcludeInterim() {
public Boolean isExcludeInterim() {
return excludeInterim;
}

Expand All @@ -119,7 +118,7 @@ public boolean isExcludeInterim() {
* When {@code true}, interim buckets will be filtered out.
* @param excludeInterim value of "exclude_interim" to be set
*/
public void setExcludeInterim(boolean excludeInterim) {
public void setExcludeInterim(Boolean excludeInterim) {
this.excludeInterim = excludeInterim;
}

Expand All @@ -130,7 +129,7 @@ public String getStart() {
/**
* Sets the value of "start" which is a timestamp.
* Only buckets whose timestamp is on or after the "start" value will be returned.
* @param start value of "start" to be set
* @param start String representation of a timestamp; may be an epoch seconds, epoch millis or an ISO string
*/
public void setStart(String start) {
this.start = start;
Expand All @@ -143,7 +142,7 @@ public String getEnd() {
/**
* Sets the value of "end" which is a timestamp.
* Only buckets whose timestamp is before the "end" value will be returned.
* @param end value of "end" to be set
* @param end String representation of a timestamp; may be an epoch seconds, epoch millis or an ISO string
*/
public void setEnd(String end) {
this.end = end;
Expand All @@ -170,7 +169,7 @@ public Double getAnomalyScore() {
* Only buckets with "anomaly_score" equal or greater will be returned.
* @param anomalyScore value of "anomaly_score".
*/
public void setAnomalyScore(double anomalyScore) {
public void setAnomalyScore(Double anomalyScore) {
this.anomalyScore = anomalyScore;
}

Expand All @@ -187,7 +186,7 @@ public void setSort(String sort) {
this.sort = sort;
}

public boolean isDescending() {
public Boolean isDescending() {
return descending;
}

Expand Down
Loading

0 comments on commit aff5658

Please sign in to comment.