Module: Elasticsearch::Persistence::Client::ClassMethods

Included in:
Elasticsearch::Persistence, Repository::Class
Defined in:
lib/elasticsearch/persistence/client.rb

Instance Method Summary collapse

Instance Method Details

#client(client = nil) ⇒ Object

Get or set the default client for this repository

Examples:

Set and configure the client for the repository class


class MyRepository
  include Elasticsearch::Persistence::Repository
  client Elasticsearch::Client.new host: 'http://localhost:9200', log: true
end

Set and configure the client for this repository instance


repository.client Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true

Perform an API request through the client


MyRepository.client.cluster.health
repository.client.cluster.health
# => { "cluster_name" => "elasticsearch" ... }


30
31
32
# File 'lib/elasticsearch/persistence/client.rb', line 30

def client client=nil
  @client = client || @client || Elasticsearch::Persistence.client
end

#client=(client) ⇒ Object

Set the default client for this repository

Examples:

Set and configure the client for the repository class


MyRepository.client = Elasticsearch::Client.new host: 'http://localhost:9200', log: true

Set and configure the client for this repository instance


repository.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true


44
45
46
# File 'lib/elasticsearch/persistence/client.rb', line 44

def client=(client)
  @client = client
end