Class: ElasticsearchDslBuilder::DSL::Search::Queries::Match

Inherits:
Query
  • Object
show all
Defined in:
lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb

Instance Attribute Summary

Attributes inherited from Query

#query, #type

Instance Method Summary collapse

Constructor Details

#initialize(field = nil, value = nil) ⇒ Match

Returns a new instance of Match.



6
7
8
9
10
11
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb', line 6

def initialize(field = nil, value = nil)
  @type = :match
  field(field)
  value(value)
  super()
end

Instance Method Details

#field(field) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb', line 13

def field(field)
  field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
  raise ArgumentError, 'field must be a String or Symbol' unless field_valid
  @field = field.to_sym
  self
end

#to_hashObject



26
27
28
29
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb', line 26

def to_hash
  @query = { @field => @value }
  super
end

#value(value) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb', line 20

def value(value)
  raise ArgumentError, 'value must be a String' unless value.instance_of?(String)
  @value = value
  self
end