Class: Elasticsearch::DSL::Search::Aggregations::Range

Inherits:
Object
  • Object
show all
Includes:
BaseAggregationComponent
Defined in:
lib/elasticsearch/dsl/search/aggregations/range.rb

Overview

A multi-bucket aggregation which returns document counts for custom numerical ranges, which define the buckets

Examples:


search do
  aggregation :clicks do
    range field: 'clicks',
          ranges: [
            { to: 10 },
            { from: 10, to: 20 }
          ]
  end
end

Using custom names for the ranges


search do
  aggregation :clicks do
    range do
      field 'clicks'
      key :low, to: 10
      key :mid, from: 10, to: 20
    end
  end
end

See Also:

Instance Method Summary collapse

Methods included from BaseAggregationComponent

included

Instance Method Details

#key(key, value) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/elasticsearch/dsl/search/aggregations/range.rb', line 59

def key(key, value)
  @hash[name].update(@args) if @args
  @hash[name][:keyed] = true unless @hash[name].has_key?(:keyed)
  @hash[name][:ranges] ||= []
  @hash[name][:ranges] << value.merge(key: key) unless @hash[name][:ranges].any? { |i| i[:key] == key }
  self
end