ElasticsearchClient GetRecordsRequest examples?

Hi all. Could anyone point me to examples of using the Java ElasticsearchClient GetRecordsRequest to return results from _ml/anomaly_detectors?

Thanks!

For anybody out there, let me answer my own question.

:slight_smile:

			final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
			credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PSWD));

//			RestClientBuilder builder = RestClient.builder(new HttpHost(HOST, 9200, "https"))			
			RestClientBuilder builder = RestClient.builder(new HttpHost(HOST, 9200))
					.setHttpClientConfigCallback(new HttpClientConfigCallback() {
						@Override
						public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
							return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
						}
					});

			RestClient restClient = builder.build();
			ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
			ElasticsearchClient client = new ElasticsearchClient(transport);

			Builder requestBuilder = new co.elastic.clients.elasticsearch.ml.GetRecordsRequest.Builder();
			requestBuilder.equals(1);
			requestBuilder.jobId("all_processes");
			requestBuilder.desc(true);
			requestBuilder.start("now-7d");

			GetRecordsRequest getRecordsRequest = requestBuilder.build();

			GetRecordsResponse getRecordsResponse = client.ml().getRecords(getRecordsRequest);
			log.info("\n\nCOUNT: " + getRecordsResponse.count() + "\n\n");

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.