Class: OpenSearch::DSL::Search::Aggregations::Range

Inherits:
Object
  • Object
show all
Includes:
BaseAggregationComponent
Defined in:
lib/opensearch/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

Instance Method Summary collapse

Methods included from BaseAggregationComponent

included

Instance Method Details

#key(key, value) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/opensearch/dsl/search/aggregations/range.rb', line 66

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