Method: ElasticsearchServerless::API::Actions#count

Defined in:
lib/elasticsearch-serverless/api/count.rb

#count(arguments = {}) ⇒ Object

Returns number of documents matching a query.

Parameters:

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

    a customizable set of options

Options Hash (arguments):

  • :index (String, Array)

    Comma-separated list of data streams, indices, and aliases to search. Supports wildcards (+*+). To search all data streams and indices, omit this parameter or use * or _all.

  • :allow_no_indices (Boolean)

    If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices. Server default: true.

  • :analyzer (String)

    Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified.

  • :default_operator (String)

    The default operator for query string query: AND or OR. This parameter can only be used when the q query string parameter is specified.

  • :df (String)

    Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified.

  • :expand_wildcards (String, Array<String>)

    Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden. Server default: open.

  • :ignore_throttled (Boolean)

    If true, concrete, expanded or aliased indices are ignored when frozen. Server default: true.

  • :ignore_unavailable (Boolean)

    If false, the request returns an error if it targets a missing or closed index.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored.

  • :min_score (Float)

    Sets the minimum _score value that documents must have to be included in the result.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :terminate_after (Integer)

    Maximum number of documents to collect for each shard. If a query reaches this limit, Elasticsearch terminates the query early. Elasticsearch collects documents before sorting.

  • :q (String)

    Query in the Lucene query string syntax.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

See Also:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/elasticsearch-serverless/api/count.rb', line 58

def count(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || "count" }

  defined_params = [:index].inject({}) do |set_variables, variable|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
    set_variables
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

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

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

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

  path   = if _index
             "#{Utils.listify(_index)}/_count"
           else
             "_count"
           end
  params = Utils.process_params(arguments)

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