Module: Elasticsearch::Persistence::Repository::Find

Included in:
Elasticsearch::Persistence::Repository
Defined in:
lib/elasticsearch/persistence/repository/find.rb

Overview

Retrieves one or more domain objects from the repository

Since:

  • 6.0.0

Instance Method Summary collapse

Instance Method Details

#exists?(id, options = {}) ⇒ true, false

Return if object exists in the repository

Examples:


repository.exists?(1)
=> true

Parameters:

  • id (String, Integer)

    The id to search.

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

    The options.

Returns:

  • (true, false)

Since:

  • 6.0.0



65
66
67
68
# File 'lib/elasticsearch/persistence/repository/find.rb', line 65

def exists?(id, options={})
  request = { index: index_name, id: id }
  client.exists(request.merge(options))
end

#find(*args) ⇒ Object, Array

Retrieve a single object or multiple objects from Elasticsearch by ID or IDs

Examples:

Retrieve a single object by ID


repository.find(1)
# => <Note ...>

Retrieve multiple objects by IDs


repository.find(1, 2)
# => [<Note ...>, <Note ...>

Returns:

  • (Object, Array)

Since:

  • 6.0.0



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elasticsearch/persistence/repository/find.rb', line 41

def find(*args)
  options  = args.last.is_a?(Hash) ? args.pop : {}
  ids      = args

  if args.size == 1
    id = args.pop
    id.is_a?(Array) ? __find_many(id, options) : __find_one(id, options)
  else
    __find_many args, options
  end
end