Link Search Menu Expand Document Documentation Menu

This version of the OpenSearch documentation is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Train

The train API operation trains a model based on a selected algorithm. Training can occur both synchronously and asynchronously.

Example request

The following examples use the k-means algorithm to train index data.

Train with k-means synchronously

POST /_plugins/_ml/_train/kmeans
{
    "parameters": {
        "centroids": 3,
        "iterations": 10,
        "distance_type": "COSINE"
    },
    "input_query": {
        "_source": ["petal_length_in_cm", "petal_width_in_cm"],
        "size": 10000
    },
    "input_index": [
        "iris_data"
    ]
}

Train with k-means asynchronously

POST /_plugins/_ml/_train/kmeans?async=true
{
    "parameters": {
        "centroids": 3,
        "iterations": 10,
        "distance_type": "COSINE"
    },
    "input_query": {
        "_source": ["petal_length_in_cm", "petal_width_in_cm"],
        "size": 10000
    },
    "input_index": [
        "iris_data"
    ]
}

Example response

Synchronous

For synchronous responses, the API returns the model_id, which can be used to get or delete a model.

{
  "model_id" : "lblVmX8BO5w8y8RaYYvN",
  "status" : "COMPLETED"
}

Asynchronous

For asynchronous responses, the API returns the task_id, which can be used to get or delete a task.

{
  "task_id" : "lrlamX8BO5w8y8Ra2otd",
  "status" : "CREATED"
}

Related articles

350 characters left

Have a question? .

Want to contribute? or .