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



53
54
55
56
# File 'lib/elasticsearch/model/multimodel.rb', line 53

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.



49
50
51
# File 'lib/elasticsearch/model/multimodel.rb', line 49

def models
  @models
end

Instance Method Details

#clientObject

Get the client common for all models

Returns:

  • Elasticsearch::Transport::Client



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

def client
  Elasticsearch::Model.client
end

#document_typeArray

Get an Array of document types used for retrieving documents when doing a search across multiple models

Returns:

  • (Array)

    the list of document types used for retrieving documents



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

def document_type
  models.map { |m| m.document_type }
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



62
63
64
# File 'lib/elasticsearch/model/multimodel.rb', line 62

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