Skip to content

[7.x] [ML] adding new flag exclude_generated that removes generated fields in GET config APIs (#63899)(#63092) #63177

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

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ static Request getJob(GetJobRequest getJobRequest) {

RequestConverters.Params params = new RequestConverters.Params();
if (getJobRequest.getAllowNoMatch() != null) {
params.putParam("allow_no_match", Boolean.toString(getJobRequest.getAllowNoMatch()));
params.putParam(GetJobRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getJobRequest.getAllowNoMatch()));
}
if (getJobRequest.getExcludeGenerated() != null) {
params.putParam(GetJobRequest.EXCLUDE_GENERATED, Boolean.toString(getJobRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -270,6 +273,9 @@ static Request getDatafeed(GetDatafeedRequest getDatafeedRequest) {
params.putParam(GetDatafeedRequest.ALLOW_NO_MATCH.getPreferredName(),
Boolean.toString(getDatafeedRequest.getAllowNoMatch()));
}
if (getDatafeedRequest.getExcludeGenerated() != null) {
params.putParam(GetDatafeedRequest.EXCLUDE_GENERATED, Boolean.toString(getDatafeedRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
}
Expand Down Expand Up @@ -645,7 +651,10 @@ static Request getDataFrameAnalytics(GetDataFrameAnalyticsRequest getRequest) {
}
}
if (getRequest.getAllowNoMatch() != null) {
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getRequest.getAllowNoMatch()));
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH, Boolean.toString(getRequest.getAllowNoMatch()));
}
if (getRequest.getExcludeGenerated() != null) {
params.putParam(GetDataFrameAnalyticsRequest.EXCLUDE_GENERATED, Boolean.toString(getRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -786,8 +795,8 @@ static Request getTrainedModels(GetTrainedModelsRequest getTrainedModelsRequest)
if (getTrainedModelsRequest.getTags() != null) {
params.putParam(GetTrainedModelsRequest.TAGS, Strings.collectionToCommaDelimitedString(getTrainedModelsRequest.getTags()));
}
if (getTrainedModelsRequest.getForExport() != null) {
params.putParam(GetTrainedModelsRequest.FOR_EXPORT, Boolean.toString(getTrainedModelsRequest.getForExport()));
if (getTrainedModelsRequest.getExcludeGenerated() != null) {
params.putParam(GetTrainedModelsRequest.EXCLUDE_GENERATED, Boolean.toString(getTrainedModelsRequest.getExcludeGenerated()));
}
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
request.addParameters(params.asMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.client.core.PageParams;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;

import java.util.Arrays;
import java.util.List;
Expand All @@ -32,11 +31,13 @@

public class GetDataFrameAnalyticsRequest implements Validatable {

public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String ALLOW_NO_MATCH = "allow_no_match";
public static final String EXCLUDE_GENERATED = "exclude_generated";

private final List<String> ids;
private Boolean allowNoMatch;
private PageParams pageParams;
private Boolean excludeGenerated;

/**
* Helper method to create a request that will get ALL Data Frame Analytics
Expand All @@ -58,6 +59,22 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getExcludeGenerated() {
return excludeGenerated;
}

/**
* Whether to ignore if a wildcard expression matches no data frame analytics.
*
Expand Down Expand Up @@ -94,11 +111,12 @@ public boolean equals(Object o) {
GetDataFrameAnalyticsRequest other = (GetDataFrameAnalyticsRequest) o;
return Objects.equals(ids, other.ids)
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(excludeGenerated, other.excludeGenerated)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, pageParams);
return Objects.hash(ids, allowNoMatch, excludeGenerated, pageParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public class GetDatafeedRequest extends ActionRequest implements ToXContentObjec

public static final ParseField DATAFEED_IDS = new ParseField("datafeed_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String EXCLUDE_GENERATED = "exclude_generated";

private static final String ALL_DATAFEEDS = "_all";
private final List<String> datafeedIds;
private Boolean allowNoMatch;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetDatafeedRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -101,14 +103,30 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getExcludeGenerated() {
return excludeGenerated;
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public int hashCode() {
return Objects.hash(datafeedIds, allowNoMatch);
return Objects.hash(datafeedIds, excludeGenerated, allowNoMatch);
}

@Override
Expand All @@ -123,7 +141,8 @@ public boolean equals(Object other) {

GetDatafeedRequest that = (GetDatafeedRequest) other;
return Objects.equals(datafeedIds, that.datafeedIds) &&
Objects.equals(allowNoMatch, that.allowNoMatch);
Objects.equals(allowNoMatch, that.allowNoMatch) &&
Objects.equals(excludeGenerated, that.excludeGenerated);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public class GetJobRequest extends ActionRequest implements ToXContentObject {

public static final ParseField JOB_IDS = new ParseField("job_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String EXCLUDE_GENERATED = "exclude_generated";

private static final String ALL_JOBS = "_all";
private final List<String> jobIds;
private Boolean allowNoMatch;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetJobRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -101,14 +103,30 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

public Boolean getExcludeGenerated() {
return excludeGenerated;
}

@Override
public ActionRequestValidationException validate() {
return null;
}

@Override
public int hashCode() {
return Objects.hash(jobIds, allowNoMatch);
return Objects.hash(jobIds, excludeGenerated, allowNoMatch);
}

@Override
Expand All @@ -123,6 +141,7 @@ public boolean equals(Object other) {

GetJobRequest that = (GetJobRequest) other;
return Objects.equals(jobIds, that.jobIds) &&
Objects.equals(excludeGenerated, that.excludeGenerated) &&
Objects.equals(allowNoMatch, that.allowNoMatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GetTrainedModelsRequest implements Validatable {
private static final String TOTAL_FEATURE_IMPORTANCE = "total_feature_importance";
private static final String FEATURE_IMPORTANCE_BASELINE = "feature_importance_baseline";
public static final String ALLOW_NO_MATCH = "allow_no_match";
public static final String FOR_EXPORT = "for_export";
public static final String EXCLUDE_GENERATED = "exclude_generated";
public static final String DECOMPRESS_DEFINITION = "decompress_definition";
public static final String TAGS = "tags";
public static final String INCLUDE = "include";
Expand All @@ -48,7 +48,7 @@ public class GetTrainedModelsRequest implements Validatable {
private Boolean allowNoMatch;
private Set<String> includes = new HashSet<>();
private Boolean decompressDefinition;
private Boolean forExport;
private Boolean excludeGenerated;
private PageParams pageParams;
private List<String> tags;

Expand Down Expand Up @@ -163,8 +163,8 @@ public GetTrainedModelsRequest setTags(String... tags) {
return setTags(Arrays.asList(tags));
}

public Boolean getForExport() {
return forExport;
public Boolean getExcludeGenerated() {
return excludeGenerated;
}

/**
Expand All @@ -173,10 +173,10 @@ public Boolean getForExport() {
* This is useful when getting the model and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed from the mode on GET
* @param excludeGenerated Boolean value indicating if certain fields should be removed from the mode on GET
*/
public GetTrainedModelsRequest setForExport(Boolean forExport) {
this.forExport = forExport;
public GetTrainedModelsRequest setExcludeGenerated(Boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
return this;
}

Expand All @@ -198,12 +198,12 @@ public boolean equals(Object o) {
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(decompressDefinition, other.decompressDefinition)
&& Objects.equals(includes, other.includes)
&& Objects.equals(forExport, other.forExport)
&& Objects.equals(excludeGenerated, other.excludeGenerated)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, pageParams, decompressDefinition, includes, forExport);
return Objects.hash(ids, allowNoMatch, pageParams, decompressDefinition, includes, excludeGenerated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ public void testGetJob() throws Exception {
// tag::get-job-request
GetJobRequest request = new GetJobRequest("get-machine-learning-job1", "get-machine-learning-job*"); // <1>
request.setAllowNoMatch(true); // <2>
request.setExcludeGenerated(false); // <3>
// end::get-job-request

// tag::get-job-execute
Expand Down Expand Up @@ -839,6 +840,7 @@ public void testGetDatafeed() throws Exception {
// tag::get-datafeed-request
GetDatafeedRequest request = new GetDatafeedRequest(datafeedId); // <1>
request.setAllowNoMatch(true); // <2>
request.setExcludeGenerated(false); // <3>
// end::get-datafeed-request

// tag::get-datafeed-execute
Expand Down Expand Up @@ -2864,6 +2866,7 @@ public void testGetDataFrameAnalytics() throws Exception {
{
// tag::get-data-frame-analytics-request
GetDataFrameAnalyticsRequest request = new GetDataFrameAnalyticsRequest("my-analytics-config"); // <1>
request.setExcludeGenerated(false); // <2>
// end::get-data-frame-analytics-request

// tag::get-data-frame-analytics-execute
Expand Down Expand Up @@ -3728,7 +3731,7 @@ public void testGetTrainedModels() throws Exception {
.setDecompressDefinition(false) // <6>
.setAllowNoMatch(true) // <7>
.setTags("regression") // <8>
.setForExport(false); // <9>
.setExcludeGenerated(false); // <9>
// end::get-trained-models-request
request.setTags((List<String>)null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ IDs, or the special wildcard `_all` to get all {dfanalytics-jobs}.
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Constructing a new GET request referencing an existing {dfanalytics-job}
<2> Optional boolean value for requesting the {dfanalytics-job} in a format that can
then be put into another cluster. Certain fields that can only be set when
the {dfanalytics-job} is created are removed.

include::../execution.asciidoc[]

Expand Down
3 changes: 3 additions & 0 deletions docs/java-rest/high-level/ml/get-datafeed.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ include-tagged::{doc-tests-file}[{api}-request]
contain wildcards.
<2> Whether to ignore if a wildcard expression matches no datafeeds.
(This includes `_all` string or when no datafeeds have been specified).
<3> Optional boolean value for requesting the datafeed in a format that can
then be put into another cluster. Certain fields that can only be set when
the datafeed is created are removed.

[id="{upid}-{api}-response"]
==== Get datafeeds response
Expand Down
3 changes: 3 additions & 0 deletions docs/java-rest/high-level/ml/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ include-tagged::{doc-tests-file}[{api}-request]
wildcards.
<2> Whether to ignore if a wildcard expression matches no {anomaly-jobs}.
(This includes `_all` string or when no jobs have been specified).
<3> Optional boolean value for requesting the job in a format that can
then be put into another cluster. Certain fields that can only be set when
the job is created are removed.

[id="{upid}-{api}-response"]
==== Get {anomaly-jobs} response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Retrieves configuration information for {dfeeds}.

`GET _ml/datafeeds/` +

`GET _ml/datafeeds/_all`
`GET _ml/datafeeds/_all`

[[ml-get-datafeed-prereqs]]
== {api-prereq-title}
Expand All @@ -36,7 +36,7 @@ comma-separated list of {dfeeds} or a wildcard expression. You can get
information for all {dfeeds} by using `_all`, by specifying `*` as the
`<feed_id>`, or by omitting the `<feed_id>`.

IMPORTANT: This API returns a maximum of 10,000 {dfeeds}.
IMPORTANT: This API returns a maximum of 10,000 {dfeeds}.

[[ml-get-datafeed-path-parms]]
== {api-path-parms-title}
Expand All @@ -57,6 +57,10 @@ all {dfeeds}.
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-datafeeds]

`exclude_generated`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=exclude-generated]

[[ml-get-datafeed-results]]
== {api-response-body-title}

Expand Down
Loading