Skip to content

Commit

Permalink
[ML] adding new flag exclude_generated that removes generated fields
Browse files Browse the repository at this point in the history
When exporting and cloning ml configurations in a cluster it can be
frustrating to remove all the fields that were generated by
the plugin. Especially as the number of these fields change
from version to version.

This flag, remove_generated, allows the GET config APIs to return
configurations with these generated fields removed.

relates to elastic#63055
  • Loading branch information
benwtrent committed Oct 19, 2020
1 parent 71aaa4a commit 707d1be
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static Request getJob(GetJobRequest getJobRequest) {
if (getJobRequest.getAllowNoMatch() != null) {
params.putParam(GetJobRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getJobRequest.getAllowNoMatch()));
}
if (getJobRequest.getForExport() != null) {
params.putParam(GetJobRequest.FOR_EXPORT, Boolean.toString(getJobRequest.getForExport()));
if (getJobRequest.getExcludeGenerated() != null) {
params.putParam(GetJobRequest.EXCLUDE_GENERATED, Boolean.toString(getJobRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -273,8 +273,8 @@ static Request getDatafeed(GetDatafeedRequest getDatafeedRequest) {
params.putParam(GetDatafeedRequest.ALLOW_NO_MATCH.getPreferredName(),
Boolean.toString(getDatafeedRequest.getAllowNoMatch()));
}
if (getDatafeedRequest.getForExport() != null) {
params.putParam(GetDatafeedRequest.FOR_EXPORT, Boolean.toString(getDatafeedRequest.getForExport()));
if (getDatafeedRequest.getExcludeGenerated() != null) {
params.putParam(GetDatafeedRequest.EXCLUDE_GENERATED, Boolean.toString(getDatafeedRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -653,8 +653,8 @@ static Request getDataFrameAnalytics(GetDataFrameAnalyticsRequest getRequest) {
if (getRequest.getAllowNoMatch() != null) {
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH, Boolean.toString(getRequest.getAllowNoMatch()));
}
if (getRequest.getForExport() != null) {
params.putParam(GetDataFrameAnalyticsRequest.FOR_EXPORT, Boolean.toString(getRequest.getForExport()));
if (getRequest.getExcludeGenerated() != null) {
params.putParam(GetDataFrameAnalyticsRequest.EXCLUDE_GENERATED, Boolean.toString(getRequest.getExcludeGenerated()));
}
request.addParameters(params.asMap());
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
public class GetDataFrameAnalyticsRequest implements Validatable {

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

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

/**
* Helper method to create a request that will get ALL Data Frame Analytics
Expand Down Expand Up @@ -65,14 +65,14 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

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

/**
Expand Down Expand Up @@ -111,12 +111,12 @@ public boolean equals(Object o) {
GetDataFrameAnalyticsRequest other = (GetDataFrameAnalyticsRequest) o;
return Objects.equals(ids, other.ids)
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(forExport, other.forExport)
&& Objects.equals(excludeGenerated, other.excludeGenerated)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, forExport, pageParams);
return Objects.hash(ids, allowNoMatch, excludeGenerated, pageParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class GetDatafeedRequest implements Validatable, ToXContentObject {

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 FOR_EXPORT = "for_export";
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 forExport;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetDatafeedRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -108,19 +108,19 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

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

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

@Override
Expand All @@ -136,7 +136,7 @@ public boolean equals(Object other) {
GetDatafeedRequest that = (GetDatafeedRequest) other;
return Objects.equals(datafeedIds, that.datafeedIds) &&
Objects.equals(allowNoMatch, that.allowNoMatch) &&
Objects.equals(forExport, that.forExport);
Objects.equals(excludeGenerated, that.excludeGenerated);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public class GetJobRequest implements Validatable, 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 FOR_EXPORT = "for_export";
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 forExport;
private Boolean excludeGenerated;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetJobRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -108,19 +108,19 @@ public Boolean getAllowNoMatch() {
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
* @param excludeGenerated Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
public void setExcludeGenerated(boolean excludeGenerated) {
this.excludeGenerated = excludeGenerated;
}

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,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.setForExport(false); // <3>
request.setExcludeGenerated(false); // <3>
// end::get-job-request

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

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

// tag::get-data-frame-analytics-execute
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,9 +57,9 @@ all {dfeeds}.
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-datafeeds]

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

[[ml-get-datafeed-results]]
== {api-response-body-title}
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/ml/anomaly-detection/apis/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using a group name, a comma-separated list of jobs, or a wildcard expression.
You can get information for all {anomaly-jobs} by using `_all`, by specifying
`*` as the `<job_id>`, or by omitting the `<job_id>`.

IMPORTANT: This API returns a maximum of 10,000 jobs.
IMPORTANT: This API returns a maximum of 10,000 jobs.

[[ml-get-job-path-parms]]
== {api-path-parms-title}
Expand All @@ -50,9 +50,9 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection-defaul
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-jobs]

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

[[ml-get-job-results]]
== {api-response-body-title}
Expand All @@ -63,7 +63,7 @@ properties, see <<ml-put-job-request-body,create {anomaly-jobs} API>>.
`create_time`::
(string) The time the job was created. For example, `1491007356077`. This
property is informational; you cannot change its value.

`finished_time`::
(string) If the job closed or failed, this is the time the job finished,
otherwise it is `null`. This property is informational; you cannot change its
Expand All @@ -83,7 +83,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-snapshot-id]
== {api-response-codes-title}

`404` (Missing resources)::
If `allow_no_match` is `false`, this code indicates that there are no
If `allow_no_match` is `false`, this code indicates that there are no
resources that match the request or only partial matches for the request.

[[ml-get-job-example]]
Expand Down
Loading

0 comments on commit 707d1be

Please sign in to comment.