Skip to content

[BUG] model_id is not actually on Ml_SearchModels_Response #1032

@bestickley

Description

@bestickley

What is the bug?

async function getModelIdByName(name: string): Promise<string | undefined> {
  const res = await osMasterClient.ml.searchModels({
    body: {
      query: {
        match: {
          name,
        },
      },
    },
  });
  const hits = res.body.hits.hits;
  if (hits.length > 1) {
    console.warn("Multiple models matching name: " + name);
  } 
  return res.body.hits.hits[0]?.model_id;
}

Above code doesn't work. model_id doesn't exist. See output:

{
    "body": {
        "took": 24,
        "timed_out": false,
        "_shards": {
            "total": 1,
            "successful": 1,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 3,
                "relation": "eq"
            },
            "max_score": 1.3036298,
            "hits": [
                {
                    "_index": ".plugins-ml-model",
                    "_id": "_QNk5ZcBCtGaatUuSnQs",
                    "_version": 1,
                    "_seq_no": 39,
                    "_primary_term": 15,
                    "_score": 1.3036298,
                    "_source": {
                        "model_version": "1",
                        "created_time": 1751900244490,
                        "last_updated_time": 1751900244490,
                        "name": "Bedrock Text Embeddings Model",
                        "is_hidden": false,
                        "connector_id": "RKqXz5cB3Mel-xH3LY64",
                        "description": "Bedrock Text Embeddings Model",
                        "model_state": "REGISTERED",
                        "model_group_id": "-wNk5ZcBCtGaatUuRnSt",
                        "algorithm": "REMOTE"
                    }
                },
...

Notice how model_id isn't on the response. My workaround is to do res.body.hits.hits[0]?._id

How can one reproduce the bug?

See above.

What is the expected behavior?

model_id would not return undefined

What is your host/environment?

AWS OpenSearch 2.19.

Do you have any screenshots?

Image

Do you have any additional context?

Add any other context about the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions