# Xpack Machine Learning Java api and Curl command

**URL:** <https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240>\
**Category:** Elasticsearch\
**Created:** [December 12, 2017, 6:24am UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240 "2017-12-12T06:24:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiouser](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jiouser](https://discuss.elastic.co/u/jiouser)\
**Post date:** [December 12, 2017, 6:24am UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240/1 "2017-12-12T06:24:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmitri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmitri/32/17997_2.png) [@dmitri](https://discuss.elastic.co/u/dmitri)\
**Post date:** [December 12, 2017, 10:53am UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240/2 "2017-12-12T10:53:12Z")

</div>

Hi,

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:

```auto
http://IP:Port/_xpack/ml/anomaly_detectors/{job_id}/results/buckets?pretty

```

More info for getting bucket results can be found [here](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/ml-get-bucket.html).

---

<div class="post-metadata">

**Author:** ![jiouser](https://avatars.discourse-cdn.com/v4/letter/j/e99b99/32.png) [@jiouser](https://discuss.elastic.co/u/jiouser)\
**Post date:** [December 12, 2017, 11:51am UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240/3 "2017-12-12T11:51:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmitri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dmitri/32/17997_2.png) [@dmitri](https://discuss.elastic.co/u/dmitri)\
**Post date:** [December 12, 2017, 12:19pm UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240/4 "2017-12-12T12:19:42Z")

</div>

Hi,

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

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

```

in order to get all jobs.

As a side note, I recommend you read the [client](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html) documentation page and, in particular, the warning about the future of the Java transport client.

I hope this helps.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 9, 2018, 12:19pm UTC](https://discuss.elastic.co/t/xpack-machine-learning-java-api-and-curl-command/111240/5 "2018-01-09T12:19:48Z")

</div>

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