Skip to content

Commit 3cbae0a

Browse files
committed
Merge branch '6.x' into ccr-6.x
* 6.x: HLRC: ML Flush job (#33187) Switch more LLREST usage to new style Requests (#33171) HLRC: Adding ML Job stats (#33183) HLREST: add reindex API (#32679) Mute testSyncerOnClosingShard [DOCS] Moves machine learning APIs to docs folder (#31118)
2 parents 64695b6 + 549ccf9 commit 3cbae0a

File tree

116 files changed

+4395
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4395
-322
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
import org.elasticsearch.client.ml.DeleteJobRequest;
2929
import org.elasticsearch.client.ml.GetBucketsRequest;
3030
import org.elasticsearch.client.ml.GetJobRequest;
31+
import org.elasticsearch.client.ml.GetJobStatsRequest;
3132
import org.elasticsearch.client.ml.GetRecordsRequest;
3233
import org.elasticsearch.client.ml.OpenJobRequest;
3334
import org.elasticsearch.client.ml.PutJobRequest;
3435
import org.elasticsearch.common.Strings;
36+
import org.elasticsearch.client.ml.FlushJobRequest;
3537

3638
import java.io.IOException;
3739

@@ -126,6 +128,36 @@ static Request getBuckets(GetBucketsRequest getBucketsRequest) throws IOExceptio
126128
return request;
127129
}
128130

131+
static Request flushJob(FlushJobRequest flushJobRequest) throws IOException {
132+
String endpoint = new EndpointBuilder()
133+
.addPathPartAsIs("_xpack")
134+
.addPathPartAsIs("ml")
135+
.addPathPartAsIs("anomaly_detectors")
136+
.addPathPart(flushJobRequest.getJobId())
137+
.addPathPartAsIs("_flush")
138+
.build();
139+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
140+
request.setEntity(createEntity(flushJobRequest, REQUEST_BODY_CONTENT_TYPE));
141+
return request;
142+
}
143+
144+
static Request getJobStats(GetJobStatsRequest getJobStatsRequest) {
145+
String endpoint = new EndpointBuilder()
146+
.addPathPartAsIs("_xpack")
147+
.addPathPartAsIs("ml")
148+
.addPathPartAsIs("anomaly_detectors")
149+
.addPathPart(Strings.collectionToCommaDelimitedString(getJobStatsRequest.getJobIds()))
150+
.addPathPartAsIs("_stats")
151+
.build();
152+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
153+
154+
RequestConverters.Params params = new RequestConverters.Params(request);
155+
if (getJobStatsRequest.isAllowNoJobs() != null) {
156+
params.putParam("allow_no_jobs", Boolean.toString(getJobStatsRequest.isAllowNoJobs()));
157+
}
158+
return request;
159+
}
160+
129161
static Request getRecords(GetRecordsRequest getRecordsRequest) throws IOException {
130162
String endpoint = new EndpointBuilder()
131163
.addPathPartAsIs("_xpack")

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

+100
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
package org.elasticsearch.client;
2020

2121
import org.elasticsearch.action.ActionListener;
22+
import org.elasticsearch.client.ml.FlushJobRequest;
23+
import org.elasticsearch.client.ml.FlushJobResponse;
24+
import org.elasticsearch.client.ml.GetJobStatsRequest;
25+
import org.elasticsearch.client.ml.GetJobStatsResponse;
26+
import org.elasticsearch.client.ml.job.stats.JobStats;
2227
import org.elasticsearch.client.ml.CloseJobRequest;
2328
import org.elasticsearch.client.ml.CloseJobResponse;
2429
import org.elasticsearch.client.ml.DeleteJobRequest;
@@ -288,6 +293,101 @@ public void getBucketsAsync(GetBucketsRequest request, RequestOptions options, A
288293
Collections.emptySet());
289294
}
290295

296+
/**
297+
* Flushes internally buffered data for the given Machine Learning Job ensuring all data sent to the has been processed.
298+
* This may cause new results to be calculated depending on the contents of the buffer
299+
*
300+
* Both flush and close operations are similar,
301+
* however the flush is more efficient if you are expecting to send more data for analysis.
302+
*
303+
* When flushing, the job remains open and is available to continue analyzing data.
304+
* A close operation additionally prunes and persists the model state to disk and the
305+
* job must be opened again before analyzing further data.
306+
*
307+
* <p>
308+
* For additional info
309+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html">Flush ML job documentation</a>
310+
*
311+
* @param request The {@link FlushJobRequest} object enclosing the `jobId` and additional request options
312+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
313+
*/
314+
public FlushJobResponse flushJob(FlushJobRequest request, RequestOptions options) throws IOException {
315+
return restHighLevelClient.performRequestAndParseEntity(request,
316+
MLRequestConverters::flushJob,
317+
options,
318+
FlushJobResponse::fromXContent,
319+
Collections.emptySet());
320+
}
321+
322+
/**
323+
* Flushes internally buffered data for the given Machine Learning Job asynchronously ensuring all data sent to the has been processed.
324+
* This may cause new results to be calculated depending on the contents of the buffer
325+
*
326+
* Both flush and close operations are similar,
327+
* however the flush is more efficient if you are expecting to send more data for analysis.
328+
*
329+
* When flushing, the job remains open and is available to continue analyzing data.
330+
* A close operation additionally prunes and persists the model state to disk and the
331+
* job must be opened again before analyzing further data.
332+
*
333+
* <p>
334+
* For additional info
335+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html">Flush ML job documentation</a>
336+
*
337+
* @param request The {@link FlushJobRequest} object enclosing the `jobId` and additional request options
338+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
339+
* @param listener Listener to be notified upon request completion
340+
*/
341+
public void flushJobAsync(FlushJobRequest request, RequestOptions options, ActionListener<FlushJobResponse> listener) {
342+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
343+
MLRequestConverters::flushJob,
344+
options,
345+
FlushJobResponse::fromXContent,
346+
listener,
347+
Collections.emptySet());
348+
}
349+
350+
/**
351+
* Gets usage statistics for one or more Machine Learning jobs
352+
*
353+
* <p>
354+
* For additional info
355+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html">Get Job stats docs</a>
356+
* </p>
357+
* @param request {@link GetJobStatsRequest} Request containing a list of jobId(s) and additional options
358+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
359+
* @return {@link GetJobStatsResponse} response object containing
360+
* the {@link JobStats} objects and the number of jobs found
361+
* @throws IOException when there is a serialization issue sending the request or receiving the response
362+
*/
363+
public GetJobStatsResponse getJobStats(GetJobStatsRequest request, RequestOptions options) throws IOException {
364+
return restHighLevelClient.performRequestAndParseEntity(request,
365+
MLRequestConverters::getJobStats,
366+
options,
367+
GetJobStatsResponse::fromXContent,
368+
Collections.emptySet());
369+
}
370+
371+
/**
372+
* Gets one or more Machine Learning job configuration info, asynchronously.
373+
*
374+
* <p>
375+
* For additional info
376+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html">Get Job stats docs</a>
377+
* </p>
378+
* @param request {@link GetJobStatsRequest} Request containing a list of jobId(s) and additional options
379+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
380+
* @param listener Listener to be notified with {@link GetJobStatsResponse} upon request completion
381+
*/
382+
public void getJobStatsAsync(GetJobStatsRequest request, RequestOptions options, ActionListener<GetJobStatsResponse> listener) {
383+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
384+
MLRequestConverters::getJobStats,
385+
options,
386+
GetJobStatsResponse::fromXContent,
387+
listener,
388+
Collections.emptySet());
389+
}
390+
291391
/**
292392
* Gets the records for a Machine Learning Job.
293393
* <p>

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import org.elasticsearch.common.xcontent.XContentType;
108108
import org.elasticsearch.index.VersionType;
109109
import org.elasticsearch.index.rankeval.RankEvalRequest;
110+
import org.elasticsearch.index.reindex.ReindexRequest;
110111
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
111112
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
112113
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
@@ -832,6 +833,21 @@ static Request clusterHealth(ClusterHealthRequest healthRequest) {
832833
return request;
833834
}
834835

836+
static Request reindex(ReindexRequest reindexRequest) throws IOException {
837+
String endpoint = new EndpointBuilder().addPathPart("_reindex").build();
838+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
839+
Params params = new Params(request)
840+
.withRefresh(reindexRequest.isRefresh())
841+
.withTimeout(reindexRequest.getTimeout())
842+
.withWaitForActiveShards(reindexRequest.getWaitForActiveShards(), ActiveShardCount.DEFAULT);
843+
844+
if (reindexRequest.getScrollTime() != null) {
845+
params.putParam("scroll", reindexRequest.getScrollTime());
846+
}
847+
request.setEntity(createEntity(reindexRequest, REQUEST_BODY_CONTENT_TYPE));
848+
return request;
849+
}
850+
835851
static Request rollover(RolloverRequest rolloverRequest) throws IOException {
836852
String endpoint = new EndpointBuilder().addPathPart(rolloverRequest.getAlias()).addPathPartAsIs("_rollover")
837853
.addPathPart(rolloverRequest.getNewIndexName()).build();
@@ -1140,10 +1156,10 @@ static Request xPackInfo(XPackInfoRequest infoRequest) {
11401156
static Request xPackGraphExplore(GraphExploreRequest exploreRequest) throws IOException {
11411157
String endpoint = endpoint(exploreRequest.indices(), exploreRequest.types(), "_xpack/graph/_explore");
11421158
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
1143-
request.setEntity(createEntity(exploreRequest, REQUEST_BODY_CONTENT_TYPE));
1159+
request.setEntity(createEntity(exploreRequest, REQUEST_BODY_CONTENT_TYPE));
11441160
return request;
1145-
}
1146-
1161+
}
1162+
11471163
static Request xPackWatcherPutWatch(PutWatchRequest putWatchRequest) {
11481164
String endpoint = new EndpointBuilder()
11491165
.addPathPartAsIs("_xpack")

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

+31-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import org.elasticsearch.common.xcontent.XContentType;
6666
import org.elasticsearch.index.rankeval.RankEvalRequest;
6767
import org.elasticsearch.index.rankeval.RankEvalResponse;
68+
import org.elasticsearch.index.reindex.BulkByScrollResponse;
69+
import org.elasticsearch.index.reindex.ReindexRequest;
6870
import org.elasticsearch.plugins.spi.NamedXContentProvider;
6971
import org.elasticsearch.rest.BytesRestResponse;
7072
import org.elasticsearch.rest.RestStatus;
@@ -323,7 +325,7 @@ public final XPackClient xpack() {
323325
* Watcher APIs on elastic.co</a> for more information.
324326
*/
325327
public WatcherClient watcher() { return watcherClient; }
326-
328+
327329
/**
328330
* Provides methods for accessing the Elastic Licensed Graph explore API that
329331
* is shipped with the default distribution of Elasticsearch. All of
@@ -332,7 +334,7 @@ public final XPackClient xpack() {
332334
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html">
333335
* Graph API on elastic.co</a> for more information.
334336
*/
335-
public GraphClient graph() { return graphClient; }
337+
public GraphClient graph() { return graphClient; }
336338

337339
/**
338340
* Provides methods for accessing the Elastic Licensed Licensing APIs that
@@ -415,6 +417,33 @@ public final void bulkAsync(BulkRequest bulkRequest, ActionListener<BulkResponse
415417
performRequestAsyncAndParseEntity(bulkRequest, RequestConverters::bulk, BulkResponse::fromXContent, listener, emptySet(), headers);
416418
}
417419

420+
/**
421+
* Executes a reindex request.
422+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html">Reindex API on elastic.co</a>
423+
* @param reindexRequest the request
424+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
425+
* @return the response
426+
* @throws IOException in case there is a problem sending the request or parsing back the response
427+
*/
428+
public final BulkByScrollResponse reindex(ReindexRequest reindexRequest, RequestOptions options) throws IOException {
429+
return performRequestAndParseEntity(
430+
reindexRequest, RequestConverters::reindex, options, BulkByScrollResponse::fromXContent, emptySet()
431+
);
432+
}
433+
434+
/**
435+
* Asynchronously executes a reindex request.
436+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html">Reindex API on elastic.co</a>
437+
* @param reindexRequest the request
438+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
439+
* @param listener the listener to be notified upon request completion
440+
*/
441+
public final void reindexAsync(ReindexRequest reindexRequest, RequestOptions options, ActionListener<BulkByScrollResponse> listener) {
442+
performRequestAsyncAndParseEntity(
443+
reindexRequest, RequestConverters::reindex, options, BulkByScrollResponse::fromXContent, listener, emptySet()
444+
);
445+
}
446+
418447
/**
419448
* Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise
420449
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized

0 commit comments

Comments
 (0)