-
Notifications
You must be signed in to change notification settings - Fork 25.6k
HLRC: Add ML get influencers API #33389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.client.ml; | ||
|
|
||
| import org.elasticsearch.action.ActionRequest; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.client.ml.job.config.Job; | ||
| import org.elasticsearch.client.ml.job.util.PageParams; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.xcontent.ObjectParser; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A request to retrieve influencers of a given job | ||
| */ | ||
| public class GetInfluencersRequest extends ActionRequest implements ToXContentObject { | ||
|
|
||
| public static final ParseField EXCLUDE_INTERIM = new ParseField("exclude_interim"); | ||
| public static final ParseField START = new ParseField("start"); | ||
| public static final ParseField END = new ParseField("end"); | ||
| public static final ParseField INFLUENCER_SCORE = new ParseField("influencer_score"); | ||
| public static final ParseField SORT = new ParseField("sort"); | ||
| public static final ParseField DESCENDING = new ParseField("desc"); | ||
|
|
||
| public static final ObjectParser<GetInfluencersRequest, Void> PARSER = new ObjectParser<>("get_influencers_request", | ||
| GetInfluencersRequest::new); | ||
|
|
||
| static { | ||
| PARSER.declareString((request, jobId) -> request.jobId = jobId, Job.ID); | ||
| PARSER.declareBoolean(GetInfluencersRequest::setExcludeInterim, EXCLUDE_INTERIM); | ||
| PARSER.declareStringOrNull(GetInfluencersRequest::setStart, START); | ||
| PARSER.declareStringOrNull(GetInfluencersRequest::setEnd, END); | ||
| PARSER.declareObject(GetInfluencersRequest::setPageParams, PageParams.PARSER, PageParams.PAGE); | ||
| PARSER.declareDouble(GetInfluencersRequest::setInfluencerScore, INFLUENCER_SCORE); | ||
| PARSER.declareString(GetInfluencersRequest::setSort, SORT); | ||
| PARSER.declareBoolean(GetInfluencersRequest::setDescending, DESCENDING); | ||
| } | ||
|
|
||
| private String jobId; | ||
|
||
| private Boolean excludeInterim; | ||
| private String start; | ||
| private String end; | ||
| private Double influencerScore; | ||
| private PageParams pageParams; | ||
| private String sort; | ||
| private Boolean descending; | ||
|
|
||
| private GetInfluencersRequest() {} | ||
|
||
|
|
||
| /** | ||
| * Constructs a request to retrieve influencers of a given job | ||
| * @param jobId id of the job to retrieve influencers of | ||
| */ | ||
| public GetInfluencersRequest(String jobId) { | ||
| this.jobId = Objects.requireNonNull(jobId); | ||
| } | ||
|
|
||
| public String getJobId() { | ||
| return jobId; | ||
| } | ||
|
|
||
| public Boolean isExcludeInterim() { | ||
| return excludeInterim; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "exclude_interim". | ||
| * When {@code true}, interim influencers will be filtered out. | ||
| * @param excludeInterim value of "exclude_interim" to be set | ||
| */ | ||
| public void setExcludeInterim(Boolean excludeInterim) { | ||
| this.excludeInterim = excludeInterim; | ||
| } | ||
|
|
||
| public String getStart() { | ||
| return start; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "start" which is a timestamp. | ||
| * Only influencers whose timestamp is on or after the "start" value will be returned. | ||
| * @param start value of "start" to be set | ||
| */ | ||
| public void setStart(String start) { | ||
| this.start = start; | ||
| } | ||
|
|
||
| public String getEnd() { | ||
| return end; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "end" which is a timestamp. | ||
| * Only influencers whose timestamp is before the "end" value will be returned. | ||
| * @param end value of "end" to be set | ||
|
||
| */ | ||
| public void setEnd(String end) { | ||
| this.end = end; | ||
| } | ||
|
|
||
| public PageParams getPageParams() { | ||
| return pageParams; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the paging parameters | ||
| * @param pageParams The paging parameters | ||
| */ | ||
| public void setPageParams(PageParams pageParams) { | ||
| this.pageParams = pageParams; | ||
| } | ||
|
|
||
| public Double getInfluencerScore() { | ||
| return influencerScore; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "influencer_score". | ||
| * Only influencers with "influencer_score" equal or greater will be returned. | ||
| * @param influencerScore value of "influencer_score". | ||
| */ | ||
| public void setInfluencerScore(Double influencerScore) { | ||
| this.influencerScore = influencerScore; | ||
| } | ||
|
|
||
| public String getSort() { | ||
| return sort; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "sort". | ||
| * Specifies the influencer field to sort on. | ||
| * @param sort value of "sort". | ||
| */ | ||
| public void setSort(String sort) { | ||
| this.sort = sort; | ||
| } | ||
|
|
||
| public Boolean isDescending() { | ||
| return descending; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the value of "desc". | ||
| * Specifies the sorting order. | ||
| * @param descending value of "desc" | ||
| */ | ||
| public void setDescending(Boolean descending) { | ||
| this.descending = descending; | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(Job.ID.getPreferredName(), jobId); | ||
| if (excludeInterim != null) { | ||
| builder.field(EXCLUDE_INTERIM.getPreferredName(), excludeInterim); | ||
| } | ||
| if (start != null) { | ||
| builder.field(START.getPreferredName(), start); | ||
| } | ||
| if (end != null) { | ||
| builder.field(END.getPreferredName(), end); | ||
| } | ||
| if (pageParams != null) { | ||
| builder.field(PageParams.PAGE.getPreferredName(), pageParams); | ||
| } | ||
| if (influencerScore != null) { | ||
| builder.field(INFLUENCER_SCORE.getPreferredName(), influencerScore); | ||
| } | ||
| if (sort != null) { | ||
| builder.field(SORT.getPreferredName(), sort); | ||
| } | ||
| if (descending != null) { | ||
| builder.field(DESCENDING.getPreferredName(), descending); | ||
| } | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(jobId, excludeInterim, influencerScore, pageParams, start, end, sort, descending); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj == null) { | ||
| return false; | ||
| } | ||
| if (getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| GetInfluencersRequest other = (GetInfluencersRequest) obj; | ||
| return Objects.equals(jobId, other.jobId) && | ||
| Objects.equals(excludeInterim, other.excludeInterim) && | ||
| Objects.equals(influencerScore, other.influencerScore) && | ||
| Objects.equals(pageParams, other.pageParams) && | ||
| Objects.equals(start, other.start) && | ||
| Objects.equals(end, other.end) && | ||
| Objects.equals(sort, other.sort) && | ||
| Objects.equals(descending, other.descending); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a
ConstructingObjectParserso that the private empty ctr can be removed.