Class: Elastic::Core::QueryAssembler

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic/core/query_assembler.rb

Instance Method Summary collapse

Constructor Details

#initialize(_index, _config) ⇒ QueryAssembler

Returns a new instance of QueryAssembler.



3
4
5
6
# File 'lib/elastic/core/query_assembler.rb', line 3

def initialize(_index, _config)
  @index = _index
  @config = _config
end

Instance Method Details

#assembleObject



8
9
10
# File 'lib/elastic/core/query_assembler.rb', line 8

def assemble
  populated_query build_hit_query
end

#assemble_aggregated(_aggs) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/elastic/core/query_assembler.rb', line 42

def assemble_aggregated(_aggs)
  query = build_base_query
  query.size = 0

  last = attach_groups(query)
  last.aggregations = _aggs

  query = grouped_query(query) if grouped?
  query
end

#assemble_idsObject



24
25
26
# File 'lib/elastic/core/query_assembler.rb', line 24

def assemble_ids
  pick_query_ids build_hit_query
end

#assemble_metric(_node) ⇒ Object



32
33
34
35
# File 'lib/elastic/core/query_assembler.rb', line 32

def assemble_metric(_node)
  query = assemble_aggregated([_node])
  single_aggregation_query query
end

#assemble_metrics(_nodes) ⇒ Object



37
38
39
40
# File 'lib/elastic/core/query_assembler.rb', line 37

def assemble_metrics(_nodes)
  query = assemble_aggregated(_nodes)
  multiple_aggregation_query query
end

#assemble_pick(_field) ⇒ Object



28
29
30
# File 'lib/elastic/core/query_assembler.rb', line 28

def assemble_pick(_field)
  pick_query_fields build_hit_query, _field
end

#assemble_totalObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/elastic/core/query_assembler.rb', line 12

def assemble_total
  query = build_base_query
  query.size = 0

  if grouped?
    attach_groups(query)
    query = grouped_query query
  end

  pick_query_totals query
end