Class: ElasticsearchDslBuilder::DSL::Search::Queries::HasChild

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

Instance Attribute Summary

Attributes inherited from Query

#type

Instance Method Summary collapse

Constructor Details

#initialize(child_type = nil) ⇒ HasChild

Returns a new instance of HasChild.



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

def initialize(child_type = nil)
  @type = :has_child
  child_type(child_type)
  super()
end

Instance Method Details

#child_type(child_type) ⇒ Object

Raises:

  • (ArgumentError)


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

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

  @child_type = child_type
  self
end

#inner_hits(inner_hits) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#query(query) ⇒ Object

Raises:

  • (ArgumentError)


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

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

  @nested_query = query.to_hash
  self
end

#to_hashObject



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

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