Method: Elasticsearch::API::MachineLearning::Actions#get_categories

Defined in:
lib/elasticsearch/api/actions/machine_learning/get_categories.rb

#get_categories(arguments = {}) ⇒ Object

Retrieves anomaly detection job results for one or more categories.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :job_id (String)

    The name of the job

  • :category_id (Long)

    The identifier of the category definition of interest

  • :from (Integer)

    skips a number of categories

  • :size (Integer)

    specifies a max number of categories to get

  • :partition_field_value (String)

    Specifies the partition to retrieve categories for. This is optional, and should never be used for jobs where per-partition categorization is disabled.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    Category selection details if not provided in URI

Raises:

  • (ArgumentError)

See Also:

[View source]

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/elasticsearch/api/actions/machine_learning/get_categories.rb', line 37

def get_categories(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || 'ml.get_categories' }

  defined_params = %i[job_id category_id].each_with_object({}) do |variable, set_variables|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'job_id' missing" unless arguments[:job_id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _job_id = arguments.delete(:job_id)

  _category_id = arguments.delete(:category_id)

  method = if body
             Elasticsearch::API::HTTP_POST
           else
             Elasticsearch::API::HTTP_GET
           end

  path = if _job_id && _category_id
           "_ml/anomaly_detectors/#{Utils.__listify(_job_id)}/results/categories/#{Utils.__listify(_category_id)}"
         else
           "_ml/anomaly_detectors/#{Utils.__listify(_job_id)}/results/categories"
         end
  params = Utils.process_params(arguments)

  Elasticsearch::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end