Get trained model statistics API

Retrieves usage information for trained models.

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Request

GET _ml/inference/_stats

GET _ml/inference/_all/_stats

GET _ml/inference/<model_id>/_stats

GET _ml/inference/<model_id>,<model_id_2>/_stats

GET _ml/inference/<model_id_pattern*>,<model_id_2>/_stats

Prerequisites

Required privileges which should be added to a custom role:

  • cluster: monitor_ml

For more information, see Security privileges and Machine learning security privileges.

Description

You can get usage information for multiple trained models in a single API request by using a comma-separated list of model IDs or a wildcard expression.

Path parameters

<model_id>

(Optional, string) The unique identifier of the trained model.

Query parameters

allow_no_match

(Optional, boolean) Specifies what to do when the request:

  • Contains wildcard expressions and there are no models that match.
  • Contains the _all string or no identifiers and there are no matches.
  • Contains wildcard expressions and there are only partial matches.

The default value is true, which returns an empty array when there are no matches and the subset of results when there are partial matches. If this parameter is false, the request returns a 404 status code when there are no matches or only partial matches.

from

(Optional, integer) Skips the specified number of models. The default value is 0.

size

(Optional, integer) Specifies the maximum number of models to obtain. The default value is 100.

Response body

count

(integer) The total number of trained model statistics that matched the requested ID patterns. Could be higher than the number of items in the trained_model_stats array as the size of the array is restricted by the supplied size parameter.

trained_model_stats

(array) An array of trained model statistics, which are sorted by the model_id value in ascending order.

Properties of trained model stats

  • model_id

    (string) The unique identifier of the trained model.

    pipeline_count

    (integer) The number of ingest pipelines that currently refer to the model.

    inference_stats

    (object) A collection of inference stats fields.

    Properties of inference stats

    • missing_all_fields_count

      (integer) The number of inference calls where all the training features for the model were missing.

      inference_count

      (integer) The total number of times the model has been called for inference. This is across all inference contexts, including all pipelines.

      cache_miss_count

      (integer) The number of times the model was loaded for inference and was not retrieved from the cache. If this number is close to the inference_count, then the cache is not being appropriately used. This can be solved by increasing the cache size or its time-to-live (TTL). See General machine learning settings for the appropriate settings.

      failure_count

      (integer) The number of failures when using the model for inference.

      timestamp

      (time units) The time when the statistics were last updated.

  1. `ingest`
  2. (object) A collection of ingest stats for the model across all nodes. The values are summations of the individual node statistics. The format matches the `ingest` section in [Nodes stats]($b347631483fdb07e.md "Nodes stats API").

Response codes

404 (Missing resources)

If allow_no_match is false, this code indicates that there are no resources that match the request or only partial matches for the request.

Examples

The following example gets usage information for all the trained models:

  1. GET _ml/inference/_stats

The API returns the following results:

  1. {
  2. "count": 2,
  3. "trained_model_stats": [
  4. {
  5. "model_id": "flight-delay-prediction-1574775339910",
  6. "pipeline_count": 0,
  7. "inference_stats": {
  8. "failure_count": 0,
  9. "inference_count": 4,
  10. "cache_miss_count": 3,
  11. "missing_all_fields_count": 0,
  12. "timestamp": 1592399986979
  13. }
  14. },
  15. {
  16. "model_id": "regression-job-one-1574775307356",
  17. "pipeline_count": 1,
  18. "inference_stats": {
  19. "failure_count": 0,
  20. "inference_count": 178,
  21. "cache_miss_count": 3,
  22. "missing_all_fields_count": 0,
  23. "timestamp": 1592399986979
  24. },
  25. "ingest": {
  26. "total": {
  27. "count": 178,
  28. "time_in_millis": 8,
  29. "current": 0,
  30. "failed": 0
  31. },
  32. "pipelines": {
  33. "flight-delay": {
  34. "count": 178,
  35. "time_in_millis": 8,
  36. "current": 0,
  37. "failed": 0,
  38. "processors": [
  39. {
  40. "inference": {
  41. "type": "inference",
  42. "stats": {
  43. "count": 178,
  44. "time_in_millis": 7,
  45. "current": 0,
  46. "failed": 0
  47. }
  48. }
  49. }
  50. ]
  51. }
  52. }
  53. }
  54. }
  55. ]
  56. }