Xpack Machine Learning Java api and Curl command

We are trying out ML feature of XPack 6.0.1. From kibana following the tutorials we are able to make it work.

However, I am trying to achieve the same using the JAVA library.

I can only get the instance of XPack and ML. However after ML we are not able to identify how to call the remaining API's espeically with no javadocs and tutorials anywhere.

xpackClient = new XPackClient(client);

machineLearningClient = xpackClient.machineLearning();

After getting machineLeaningClient , say I want to fetch all the jobs which are configured. We are unable to get that.

Can anyone please help/suggest.

Also, the curl command seems to be not working for me.

curl --user username:password -XGET "http://IP:Port/_xpack/ml/results/buckets/?pretty"

I run into exception:

No handler found for uri [/_xpack/ml/results/buckets/?pretty] and method [GET]

Can anyone please guide/suggest on java api as well as tell why curl command is not working.


With regard to your first issue, have you tried using the getJobs method of the MachineLearningClient? Are you getting an error?

With regard to the curl command, the URI you are using is incorrect. It should be:


More info for getting bucket results can be found here.

Hi dmitri.

I tried using the getJobs method of MachineLearningClient but I am unable to identify what kind of Request object I have to pass. How do i create request object.

Can you please help with a code snippet for creating a request and passing that request object as an input to getJobs method.

For part 2, thanks. I missed the job_id part from the URL.

Can you please assist on part 1 as we are keen on using Java api for ML.


It works like all other actions; you need to pass in a GetJobsAction.Request object. For example:

getJobs(new GetJobsAction.Request("*"));

in order to get all jobs.

As a side note, I recommend you read the client documentation page and, in particular, the warning about the future of the Java transport client.

I hope this helps.

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