Class: Elasticsearch::Model::Multimodel

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/model/multimodel.rb

Overview

Wraps a collection of models when querying multiple indices

See Also:

  • search

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*models) ⇒ Multimodel

Returns a new instance of Multimodel.

Parameters:

  • models (Class)

    The list of models across which the search will be performed



69
70
71
72
# File 'lib/elasticsearch/model/multimodel.rb', line 69

def initialize(*models)
  @models = models.flatten
  @models = Model::Registry.all if @models.empty?
end

Instance Attribute Details

#modelsObject (readonly)

Returns the value of attribute models.



65
66
67
# File 'lib/elasticsearch/model/multimodel.rb', line 65

def models
  @models
end

Instance Method Details

#clientObject

Get the client common for all models

Returns:

  • Elastic::Transport::Client



86
87
88
# File 'lib/elasticsearch/model/multimodel.rb', line 86

def client
  Elasticsearch::Model.client
end

#index_nameArray

Get an Array of index names used for retrieving documents when doing a search across multiple models

Returns:

  • (Array)

    the list of index names used for retrieving documents



78
79
80
# File 'lib/elasticsearch/model/multimodel.rb', line 78

def index_name
  models.map { |m| m.index_name }
end