Class: ElasticsearchDslBuilder::DSL::Search::Aggregations::DateHistogram

Inherits:
Aggregation
  • Object
show all
Defined in:
lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb

Instance Method Summary collapse

Methods inherited from Aggregation

#aggregation

Constructor Details

#initialize(field = nil, interval = nil) ⇒ DateHistogram

Returns a new instance of DateHistogram.



6
7
8
9
10
11
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 6

def initialize(field = nil, interval = nil)
  @type = :date_histogram
  field(field)
  interval(interval)
  super()
end

Instance Method Details

#extended_bounds_max(max) ⇒ Object



42
43
44
45
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 42

def extended_bounds_max(max)
  @extended_bounds_max = max
  self
end

#extended_bounds_min(min) ⇒ Object



37
38
39
40
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 37

def extended_bounds_min(min)
  @extended_bounds_min = min
  self
end

#field(field) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 13

def field(field)
  raise ArgumentError, 'field must be a String' unless field.instance_of?(String)
  @field = field
  self
end

#format(format) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 25

def format(format)
  raise ArgumentError, 'format must be a String' unless format.instance_of?(String)
  @format = format
  self
end

#interval(interval) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 19

def interval(interval)
  raise ArgumentError, 'interval must be a String' unless interval.instance_of?(String)
  @interval = interval
  self
end

#min_doc_count(min) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 31

def min_doc_count(min)
  raise ArgumentError, 'min_doc_count must be Numeric' unless min.is_a?(Numeric)
  @min_doc_count = min
  self
end

#to_hashObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/date_histogram.rb', line 47

def to_hash
  @aggregation = { field: @field, interval: @interval }
  @aggregation.update(format: @format) if @format
  @aggregation.update(min_doc_count: @min_doc_count) if @min_doc_count

  extended_bounds = {}
  extended_bounds.update(min: @extended_bounds_min) if @extended_bounds_min
  extended_bounds.update(max: @extended_bounds_max) if @extended_bounds_max
  @aggregation.update(extended_bounds: extended_bounds) unless extended_bounds.empty?
  super
end