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



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

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.



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

def models
  @models
end

Instance Method Details

#clientObject

Get the client common for all models

Returns:

  • Elasticsearch::Transport::Client



95
96
97
# File 'lib/elasticsearch/model/multimodel.rb', line 95

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



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

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



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

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