Inference Bucket Aggregation

A parent pipeline aggregation which loads a pre-trained model and performs inference on the collated result fields from the parent bucket aggregation.

To use the inference bucket aggregation, you need to have the same security privileges that are required for using the Get trained model.

Syntax

A inference aggregation looks like this in isolation:

  1. {
  2. "inference": {
  3. "model_id": "a_model_for_inference",
  4. "inference_config": {
  5. "regression_config": {
  6. "num_top_feature_importance_values": 2
  7. }
  8. },
  9. "buckets_path": {
  10. "avg_cost": "avg_agg",
  11. "max_cost": "max_agg"
  12. }
  13. }
  14. }

The ID of model to use.

The optional inference config which overrides the model’s default settings

Map the value of avg_agg to the model’s input field avg_cost

Table 71. inference Parameters

Parameter NameDescriptionRequiredDefault Value

model_id

The ID of the model to load and infer against

Required

-

inference_config

Contains the inference type and its options. There are two types: regression and classification

Optional

-

buckets_path

Defines the paths to the input aggregations and maps the aggregation names to the field names expected by the model. See buckets_path Syntax for more details

Required

-

Configuration options for inference models

The inference_config setting is optional and usually isn’t required as the pre-trained models come equipped with sensible defaults. In the context of aggregations some options can overridden for each of the 2 types of model.

Configuration options for regression models

num_top_feature_importance_values

(Optional, integer) Specifies the maximum number of feature importance values per document. By default, it is zero and no feature importance calculation occurs.

Configuration options for classification models

num_top_classes

(Optional, integer) Specifies the number of top class predictions to return. Defaults to 0.

num_top_feature_importance_values

(Optional, integer) Specifies the maximum number of feature importance values per document. By default, it is zero and no feature importance calculation occurs.

prediction_field_type

(Optional, string) Specifies the type of the predicted field to write. Acceptable values are: string, number, boolean. When boolean is provided 1.0 is transformed to true and 0.0 to false.

Example

The following snippet aggregates a web log by client_ip and extracts a number of features via metric and bucket sub-aggregations as input to the inference aggregation configured with a model trained to identify suspicious client IPs:

  1. GET kibana_sample_data_logs/_search
  2. {
  3. "size": 0,
  4. "aggs": {
  5. "client_ip": {
  6. "composite": {
  7. "sources": [
  8. {
  9. "client_ip": {
  10. "terms": {
  11. "field": "clientip"
  12. }
  13. }
  14. }
  15. ]
  16. },
  17. "aggs": {
  18. "url_dc": {
  19. "cardinality": {
  20. "field": "url.keyword"
  21. }
  22. },
  23. "bytes_sum": {
  24. "sum": {
  25. "field": "bytes"
  26. }
  27. },
  28. "geo_src_dc": {
  29. "cardinality": {
  30. "field": "geo.src"
  31. }
  32. },
  33. "geo_dest_dc": {
  34. "cardinality": {
  35. "field": "geo.dest"
  36. }
  37. },
  38. "responses_total": {
  39. "value_count": {
  40. "field": "timestamp"
  41. }
  42. },
  43. "success": {
  44. "filter": {
  45. "term": {
  46. "response": "200"
  47. }
  48. }
  49. },
  50. "error404": {
  51. "filter": {
  52. "term": {
  53. "response": "404"
  54. }
  55. }
  56. },
  57. "error503": {
  58. "filter": {
  59. "term": {
  60. "response": "503"
  61. }
  62. }
  63. },
  64. "malicious_client_ip": {
  65. "inference": {
  66. "model_id": "malicious_clients_model",
  67. "buckets_path": {
  68. "response_count": "responses_total",
  69. "url_dc": "url_dc",
  70. "bytes_sum": "bytes_sum",
  71. "geo_src_dc": "geo_src_dc",
  72. "geo_dest_dc": "geo_dest_dc",
  73. "success": "success._count",
  74. "error404": "error404._count",
  75. "error503": "error503._count"
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }

A composite bucket aggregation that aggregates the data by client_ip.

A series of metrics and bucket sub-aggregations.

Inference bucket aggregation that contains the model ID and maps the aggregation names to the model’s input fields.