Class: Blocktrain::Aggregations::TermsAggregation

Inherits:
Blocktrain::Aggregation show all
Defined in:
lib/blocktrain/aggregations/terms_aggregation.rb

Instance Method Summary collapse

Methods inherited from Blocktrain::Aggregation

#body

Methods inherited from Query

#address_query, #body, #build_query, #filtered_filter, #filtered_query, #hits, #parse_datetime

Constructor Details

#initialize(options = {}) ⇒ TermsAggregation

Returns a new instance of TermsAggregation.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/blocktrain/aggregations/terms_aggregation.rb', line 5

def initialize(options = {})
  @term = options.fetch(:term, nil)
  raise ArgumentError.new("TermAggregation requires a term: argument") unless @term
  super
end

Instance Method Details

#aggsObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/blocktrain/aggregations/terms_aggregation.rb', line 19

def aggs
  {
    langs: {
      terms: {
        field: @term,
        size: 0
      }
    }
  }
end

#queryObject



11
12
13
14
15
16
17
# File 'lib/blocktrain/aggregations/terms_aggregation.rb', line 11

def query
  {
    filtered: {
      filter: filtered_filter
    }
  }
end

#resultsObject



30
31
32
# File 'lib/blocktrain/aggregations/terms_aggregation.rb', line 30

def results
  result['aggregations']['langs']['buckets']
end