Class: ElasticsearchDslBuilder::DSL::Search::Queries::HasParent

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

Instance Attribute Summary

Attributes inherited from Query

#type

Instance Method Summary collapse

Constructor Details

#initialize(parent_type) ⇒ HasParent

Returns a new instance of HasParent.



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

def initialize(parent_type)
  @type = :has_parent
  parent_type(parent_type)
  super()
end

Instance Method Details

#inner_hits(inner_hits) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/has_parent.rb', line 33

def inner_hits(inner_hits)
  raise ArgumentError, 'inner_hits must be an InnerHits object' unless inner_hits.instance_of?(InnerHits)
  @inner_hits = inner_hits.to_hash
  self
end

#parent_type(parent_type) ⇒ Object

Raises:

  • (ArgumentError)


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

def parent_type(parent_type)
  raise ArgumentError, 'parent_type must be a String' unless parent_type.instance_of?(String)

  @parent_type = parent_type
  self
end

#query(query) ⇒ Object

Raises:

  • (ArgumentError)


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

def query(query)
  raise ArgumentError, 'query must extend type Queries::Query' unless query.is_a?(Query)

  @nested_query = query.to_hash
  self
end

#score(score) ⇒ Object

Raises:

  • (ArgumentError)


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

def score(score)
  raise ArgumentError, 'score must be a boolean' unless !!score == score

  @score = score
  self
end

#to_hashObject



39
40
41
42
43
44
45
46
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/has_parent.rb', line 39

def to_hash
  @query = {}
  @query.update(parent_type: @parent_type) if @parent_type
  @query.update(score: @score) if @score
  @query.update(query: @nested_query) if @nested_query
  @query.update(inner_hits: @inner_hits) if @inner_hits
  super
end