Class: ElasticQuery::QueryCollection

Inherits:
BaseQuery
  • Object
show all
Defined in:
lib/elastic_query/query_collection.rb

Overview

This class represents Arrays of contitions like

Which woult be euqivalent to

Examples:

{
  must: [
    { match: { name: "mike" } }
    { term: { gender: "male" } }
  ]
}
QueryCollection.new(:must,
  [
    Query.new(match: { name: "mike" }),
    Query.new(term: { gender: "male" })
  ]
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, queries) ⇒ QueryCollection

Returns a new instance of QueryCollection.

Parameters:

  • key (Symbol)

    the key

  • the (Array<Query>)

    queries



26
27
28
29
# File 'lib/elastic_query/query_collection.rb', line 26

def initialize(key, queries)
  @key = key
  @queries = queries
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



22
23
24
# File 'lib/elastic_query/query_collection.rb', line 22

def key
  @key
end

#queriesObject

Returns the value of attribute queries.



22
23
24
# File 'lib/elastic_query/query_collection.rb', line 22

def queries
  @queries
end

Instance Method Details

#to_hashObject



31
32
33
34
35
# File 'lib/elastic_query/query_collection.rb', line 31

def to_hash
  {
    key => queries.map(&:to_hash)
  }
end