Skip to content

Commit 9084418

Browse files
authored
[ML][Data Frame] Add support for allow_no_match for endpoints (#43490)
* [ML][Data Frame] Add support for allow_no_match parameter in endpoints Adds support for: * Get Transforms * Get Transforms stats * stop transforms
1 parent e737361 commit 9084418

File tree

28 files changed

+242
-39
lines changed

28 files changed

+242
-39
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/DataFrameRequestConverters.java

+25-15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE;
3939
import static org.elasticsearch.client.RequestConverters.createEntity;
40+
import static org.elasticsearch.client.dataframe.GetDataFrameTransformRequest.ALLOW_NO_MATCH;
4041

4142
final class DataFrameRequestConverters {
4243

@@ -64,6 +65,9 @@ static Request getDataFrameTransform(GetDataFrameTransformRequest getRequest) {
6465
if (getRequest.getPageParams() != null && getRequest.getPageParams().getSize() != null) {
6566
request.addParameter(PageParams.SIZE.getPreferredName(), getRequest.getPageParams().getSize().toString());
6667
}
68+
if (getRequest.getAllowNoMatch() != null) {
69+
request.addParameter(ALLOW_NO_MATCH, getRequest.getAllowNoMatch().toString());
70+
}
6771
return request;
6872
}
6973

@@ -91,21 +95,24 @@ static Request startDataFrameTransform(StartDataFrameTransformRequest startReque
9195
}
9296

9397
static Request stopDataFrameTransform(StopDataFrameTransformRequest stopRequest) {
94-
String endpoint = new RequestConverters.EndpointBuilder()
95-
.addPathPartAsIs("_data_frame", "transforms")
96-
.addPathPart(stopRequest.getId())
97-
.addPathPartAsIs("_stop")
98-
.build();
99-
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
100-
RequestConverters.Params params = new RequestConverters.Params();
101-
if (stopRequest.getWaitForCompletion() != null) {
102-
params.withWaitForCompletion(stopRequest.getWaitForCompletion());
103-
}
104-
if (stopRequest.getTimeout() != null) {
105-
params.withTimeout(stopRequest.getTimeout());
106-
}
107-
request.addParameters(params.asMap());
108-
return request;
98+
String endpoint = new RequestConverters.EndpointBuilder()
99+
.addPathPartAsIs("_data_frame", "transforms")
100+
.addPathPart(stopRequest.getId())
101+
.addPathPartAsIs("_stop")
102+
.build();
103+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
104+
RequestConverters.Params params = new RequestConverters.Params();
105+
if (stopRequest.getWaitForCompletion() != null) {
106+
params.withWaitForCompletion(stopRequest.getWaitForCompletion());
107+
}
108+
if (stopRequest.getTimeout() != null) {
109+
params.withTimeout(stopRequest.getTimeout());
110+
}
111+
if (stopRequest.getAllowNoMatch() != null) {
112+
request.addParameter(ALLOW_NO_MATCH, stopRequest.getAllowNoMatch().toString());
113+
}
114+
request.addParameters(params.asMap());
115+
return request;
109116
}
110117

111118
static Request previewDataFrameTransform(PreviewDataFrameTransformRequest previewRequest) throws IOException {
@@ -130,6 +137,9 @@ static Request getDataFrameTransformStats(GetDataFrameTransformStatsRequest stat
130137
if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getSize() != null) {
131138
request.addParameter(PageParams.SIZE.getPreferredName(), statsRequest.getPageParams().getSize().toString());
132139
}
140+
if (statsRequest.getAllowNoMatch() != null) {
141+
request.addParameter(ALLOW_NO_MATCH, statsRequest.getAllowNoMatch().toString());
142+
}
133143
return request;
134144
}
135145
}

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/GetDataFrameTransformRequest.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
public class GetDataFrameTransformRequest implements Validatable {
3232

33+
public static final String ALLOW_NO_MATCH = "allow_no_match";
3334
/**
3435
* Helper method to create a request that will get ALL Data Frame Transforms
3536
* @return new {@link GetDataFrameTransformRequest} object for the id "_all"
@@ -40,6 +41,7 @@ public static GetDataFrameTransformRequest getAllDataFrameTransformsRequest() {
4041

4142
private final List<String> ids;
4243
private PageParams pageParams;
44+
private Boolean allowNoMatch;
4345

4446
public GetDataFrameTransformRequest(String... ids) {
4547
this.ids = Arrays.asList(ids);
@@ -57,6 +59,14 @@ public void setPageParams(PageParams pageParams) {
5759
this.pageParams = pageParams;
5860
}
5961

62+
public Boolean getAllowNoMatch() {
63+
return allowNoMatch;
64+
}
65+
66+
public void setAllowNoMatch(Boolean allowNoMatch) {
67+
this.allowNoMatch = allowNoMatch;
68+
}
69+
6070
@Override
6171
public Optional<ValidationException> validate() {
6272
if (ids == null || ids.isEmpty()) {
@@ -70,7 +80,7 @@ public Optional<ValidationException> validate() {
7080

7181
@Override
7282
public int hashCode() {
73-
return Objects.hash(ids, pageParams);
83+
return Objects.hash(ids, pageParams, allowNoMatch);
7484
}
7585

7686
@Override
@@ -83,6 +93,8 @@ public boolean equals(Object obj) {
8393
return false;
8494
}
8595
GetDataFrameTransformRequest other = (GetDataFrameTransformRequest) obj;
86-
return Objects.equals(ids, other.ids) && Objects.equals(pageParams, other.pageParams);
96+
return Objects.equals(ids, other.ids)
97+
&& Objects.equals(pageParams, other.pageParams)
98+
&& Objects.equals(allowNoMatch, other.allowNoMatch);
8799
}
88100
}

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/GetDataFrameTransformStatsRequest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public class GetDataFrameTransformStatsRequest implements Validatable {
3030
private final String id;
3131
private PageParams pageParams;
32+
private Boolean allowNoMatch;
3233

3334
public GetDataFrameTransformStatsRequest(String id) {
3435
this.id = id;
@@ -46,6 +47,14 @@ public void setPageParams(PageParams pageParams) {
4647
this.pageParams = pageParams;
4748
}
4849

50+
public Boolean getAllowNoMatch() {
51+
return allowNoMatch;
52+
}
53+
54+
public void setAllowNoMatch(Boolean allowNoMatch) {
55+
this.allowNoMatch = allowNoMatch;
56+
}
57+
4958
@Override
5059
public Optional<ValidationException> validate() {
5160
if (id == null) {
@@ -59,7 +68,7 @@ public Optional<ValidationException> validate() {
5968

6069
@Override
6170
public int hashCode() {
62-
return Objects.hash(id, pageParams);
71+
return Objects.hash(id, pageParams, allowNoMatch);
6372
}
6473

6574
@Override
@@ -72,6 +81,8 @@ public boolean equals(Object obj) {
7281
return false;
7382
}
7483
GetDataFrameTransformStatsRequest other = (GetDataFrameTransformStatsRequest) obj;
75-
return Objects.equals(id, other.id) && Objects.equals(pageParams, other.pageParams);
84+
return Objects.equals(id, other.id)
85+
&& Objects.equals(pageParams, other.pageParams)
86+
&& Objects.equals(allowNoMatch, other.allowNoMatch);
7687
}
7788
}

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/StopDataFrameTransformRequest.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class StopDataFrameTransformRequest implements Validatable {
3131
private final String id;
3232
private Boolean waitForCompletion;
3333
private TimeValue timeout;
34+
private Boolean allowNoMatch;
3435

3536
public StopDataFrameTransformRequest(String id) {
3637
this.id = id;
@@ -64,6 +65,14 @@ public TimeValue getTimeout() {
6465
return timeout;
6566
}
6667

68+
public Boolean getAllowNoMatch() {
69+
return allowNoMatch;
70+
}
71+
72+
public void setAllowNoMatch(Boolean allowNoMatch) {
73+
this.allowNoMatch = allowNoMatch;
74+
}
75+
6776
@Override
6877
public Optional<ValidationException> validate() {
6978
if (id == null) {
@@ -77,7 +86,7 @@ public Optional<ValidationException> validate() {
7786

7887
@Override
7988
public int hashCode() {
80-
return Objects.hash(id, waitForCompletion, timeout);
89+
return Objects.hash(id, waitForCompletion, timeout, allowNoMatch);
8190
}
8291

8392
@Override
@@ -92,7 +101,8 @@ public boolean equals(Object obj) {
92101
StopDataFrameTransformRequest other = (StopDataFrameTransformRequest) obj;
93102
return Objects.equals(this.id, other.id)
94103
&& Objects.equals(this.waitForCompletion, other.waitForCompletion)
95-
&& Objects.equals(this.timeout, other.timeout);
104+
&& Objects.equals(this.timeout, other.timeout)
105+
&& Objects.equals(this.allowNoMatch, other.allowNoMatch);
96106
}
97107

98108
}

client/rest-high-level/src/test/java/org/elasticsearch/client/DataFrameRequestConvertersTests.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.Collections;
4747
import java.util.List;
4848

49+
import static org.elasticsearch.client.dataframe.GetDataFrameTransformRequest.ALLOW_NO_MATCH;
4950
import static org.hamcrest.Matchers.allOf;
5051
import static org.hamcrest.Matchers.equalTo;
5152
import static org.hamcrest.Matchers.hasEntry;
@@ -115,7 +116,6 @@ public void testStopDataFrameTransform() {
115116
}
116117
StopDataFrameTransformRequest stopRequest = new StopDataFrameTransformRequest(id, waitForCompletion, timeValue);
117118

118-
119119
Request request = DataFrameRequestConverters.stopDataFrameTransform(stopRequest);
120120
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
121121
assertThat(request.getEndpoint(), equalTo("/_data_frame/transforms/" + stopRequest.getId() + "/_stop"));
@@ -133,6 +133,11 @@ public void testStopDataFrameTransform() {
133133
} else {
134134
assertFalse(request.getParameters().containsKey("timeout"));
135135
}
136+
137+
assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));
138+
stopRequest.setAllowNoMatch(randomBoolean());
139+
request = DataFrameRequestConverters.stopDataFrameTransform(stopRequest);
140+
assertEquals(stopRequest.getAllowNoMatch(), Boolean.parseBoolean(request.getParameters().get(ALLOW_NO_MATCH)));
136141
}
137142

138143
public void testPreviewDataFrameTransform() throws IOException {
@@ -158,6 +163,7 @@ public void testGetDataFrameTransformStats() {
158163

159164
assertFalse(request.getParameters().containsKey("from"));
160165
assertFalse(request.getParameters().containsKey("size"));
166+
assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));
161167

162168
getStatsRequest.setPageParams(new PageParams(0, null));
163169
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
@@ -172,6 +178,10 @@ public void testGetDataFrameTransformStats() {
172178
getStatsRequest.setPageParams(new PageParams(0, 10));
173179
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
174180
assertThat(request.getParameters(), allOf(hasEntry("from", "0"), hasEntry("size", "10")));
181+
182+
getStatsRequest.setAllowNoMatch(false);
183+
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
184+
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
175185
}
176186

177187
public void testGetDataFrameTransform() {
@@ -183,6 +193,7 @@ public void testGetDataFrameTransform() {
183193

184194
assertFalse(request.getParameters().containsKey("from"));
185195
assertFalse(request.getParameters().containsKey("size"));
196+
assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));
186197

187198
getRequest.setPageParams(new PageParams(0, null));
188199
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
@@ -197,6 +208,10 @@ public void testGetDataFrameTransform() {
197208
getRequest.setPageParams(new PageParams(0, 10));
198209
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
199210
assertThat(request.getParameters(), allOf(hasEntry("from", "0"), hasEntry("size", "10")));
211+
212+
getRequest.setAllowNoMatch(false);
213+
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
214+
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
200215
}
201216

202217
public void testGetDataFrameTransform_givenMulitpleIds() {

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/DataFrameTransformDocumentationIT.java

+7
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public void testStartStop() throws IOException, InterruptedException {
263263
// tag::stop-data-frame-transform-request-options
264264
request.setWaitForCompletion(Boolean.TRUE); // <1>
265265
request.setTimeout(TimeValue.timeValueSeconds(30)); // <2>
266+
request.setAllowNoMatch(true); // <3>
266267
// end::stop-data-frame-transform-request-options
267268

268269
// tag::stop-data-frame-transform-execute
@@ -506,6 +507,11 @@ public void testGetStats() throws IOException, InterruptedException {
506507
new GetDataFrameTransformStatsRequest(id); // <1>
507508
// end::get-data-frame-transform-stats-request
508509

510+
// tag::get-data-frame-transform-stats-request-options
511+
request.setPageParams(new PageParams(0, 100)); // <1>
512+
request.setAllowNoMatch(true); // <2>
513+
// end::get-data-frame-transform-stats-request-params
514+
509515
{
510516
// tag::get-data-frame-transform-stats-execute
511517
GetDataFrameTransformStatsResponse response =
@@ -597,6 +603,7 @@ public void testGetDataFrameTransform() throws IOException, InterruptedException
597603

598604
// tag::get-data-frame-transform-request-options
599605
request.setPageParams(new PageParams(0, 100)); // <1>
606+
request.setAllowNoMatch(true); // <2>
600607
// end::get-data-frame-transform-request-options
601608

602609
// tag::get-data-frame-transform-execute

docs/java-rest/high-level/dataframe/get_data_frame.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ include-tagged::{doc-tests-file}[{api}-request-options]
3232
<1> The page parameters `from` and `size`. `from` specifies the number of
3333
{dataframe-transforms} to skip. `size` specifies the maximum number of
3434
{dataframe-transforms} to get. Defaults to `0` and `100` respectively.
35+
<2> Whether to ignore if a wildcard expression matches no transforms.
3536

3637

3738
include::../execution.asciidoc[]

docs/java-rest/high-level/dataframe/get_data_frame_stats.asciidoc

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ include-tagged::{doc-tests-file}[{api}-request]
2222
--------------------------------------------------
2323
<1> Constructing a new GET Stats request referencing an existing {dataframe-transform}
2424

25+
==== Optional Arguments
26+
27+
The following arguments are optional.
28+
29+
["source","java",subs="attributes,callouts,macros"]
30+
--------------------------------------------------
31+
include-tagged::{doc-tests-file}[{api}-request-options]
32+
--------------------------------------------------
33+
<1> The page parameters `from` and `size`. `from` specifies the number of data frame transform stats to skip.
34+
`size` specifies the maximum number of data frame transform stats to get.
35+
Defaults to `0` and `100` respectively.
36+
<2> Whether to ignore if a wildcard expression matches no transforms.
37+
2538

2639
include::../execution.asciidoc[]
2740

docs/java-rest/high-level/dataframe/stop_data_frame.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ include-tagged::{doc-tests-file}[{api}-request-options]
3232
--------------------------------------------------
3333
<1> If true wait for the data frame task to stop before responding
3434
<2> Controls the amount of time to wait until the {dataframe-job} stops.
35+
<3> Whether to ignore if a wildcard expression matches no transforms.
3536

3637
include::../execution.asciidoc[]
3738

docs/reference/data-frames/apis/get-transform-stats.asciidoc

+6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ Retrieves usage information for {dataframe-transforms}.
3636
specify one of these options, the API returns information for all
3737
{dataframe-transforms}.
3838

39+
==== Query Parameters
40+
3941
`from`::
4042
(integer) Skips the specified number of {dataframe-transforms}. The
4143
default value is `0`.
4244

4345
`size`::
4446
(integer) Specifies the maximum number of {dataframe-transforms} to obtain. The default value is `100`.
4547

48+
`allow_no_match`::
49+
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
50+
This includes `_all` string or when no transforms have been specified. The default is `true`.
51+
4652
==== Results
4753

4854
The API returns the following information:

docs/reference/data-frames/apis/get-transform.asciidoc

+6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ Retrieves configuration information for {dataframe-transforms}.
3535
specify one of these options, the API returns information for all
3636
{dataframe-transforms}.
3737

38+
==== Query Parameters
39+
3840
`from`::
3941
(integer) Skips the specified number of {dataframe-transforms}. The
4042
default value is `0`.
4143

4244
`size`::
4345
(integer) Specifies the maximum number of {dataframe-transforms} to obtain. The default value is `100`.
4446

47+
`allow_no_match`::
48+
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
49+
This includes `_all` string or when no transforms have been specified. The default is `true`.
50+
4551
==== Results
4652

4753
The API returns the following information:

docs/reference/data-frames/apis/stop-transform.asciidoc

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ All {dataframe-transforms} can be stopped by using `_all` or `*` as the `<data_f
4545
timeout exception is thrown, the stop request is still processing and
4646
eventually moves the transform to `STOPPED`. The timeout simply means the API
4747
call itself timed out while waiting for the status change. Defaults to `30s`
48-
48+
49+
`allow_no_match`::
50+
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
51+
This includes `_all` string or when no transforms have been specified. The default is `true`.
52+
4953
//==== Request Body
5054
==== Authorization
5155

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/DataFrameField.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class DataFrameField {
3333
public static final ParseField TIME_BASED_SYNC = new ParseField("time");
3434
public static final ParseField DELAY = new ParseField("delay");
3535

36+
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
3637
/**
3738
* Fields for checkpointing
3839
*/

0 commit comments

Comments
 (0)