Method: ChefAPI::Resource::Search.query

Defined in:
lib/chef-api/resources/search.rb

.query(index, query = '*:*', options = {}) ⇒ self

Parameters:

  • index (String)

    the name of the index to search

  • query (String) (defaults to: '*:*')

    the query string

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

    the query string

Returns:

  • (self)

    the current resource



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef-api/resources/search.rb', line 25

def query(index, query = '*:*', options = {})
  return nil if index.nil?

  params = {}.tap do |o|
    o[:q]     = query
    o[:rows]  = options[:rows]  || 1000
    o[:sort]  = options[:sort]  || 'X_CHEF_id_CHEF_X'
    o[:start] = options[:start] || 0
  end

  path = expanded_collection_path(index: index.to_s)
  response = connection.get(path, params)
  from_json(response, index: index.to_s)
end