Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::DateHistogram

Inherits:
Aggregation
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb

Overview

Represents a date_histogram aggregation in Elasticsearch. Information about this type of aggregation can be found in: www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-datehistogram-aggregation

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Methods inherited from Aggregation

#aggs

Constructor Details

#initialize(name, field:, calendar_interval:, format: nil) ⇒ DateHistogram

Returns a new instance of DateHistogram.

Parameters:

  • name (String)

    The name used by Elasticsearch to identify each of the aggregations.

  • field (String)

    The field over which the date histogram should be performed. This field MUST be a date or date range field.

  • calendar_interval (String)

    The interval that should be used for the histogram. For a list of accepted intervals check the aggregation’s documentation. This must be a single calendar unit. I.e. 1d is accepted but 2d is not.

  • format (String) (defaults to: nil)

    The format in which the date interval keys should be represented. For information on what this format can be check the aggregation’s documentation.



24
25
26
27
28
29
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 24

def initialize(name, field:, calendar_interval:, format: nil)
  @field = field
  @calendar_interval = calendar_interval
  @format = format
  super(name)
end

Instance Attribute Details

#calendar_intervalObject (readonly)

Returns the value of attribute calendar_interval.



11
12
13
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 11

def calendar_interval
  @calendar_interval
end

#fieldObject (readonly)

Returns the value of attribute field.



11
12
13
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 11

def field
  @field
end

#formatObject (readonly)

Returns the value of attribute format.



11
12
13
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 11

def format
  @format
end

Instance Method Details

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



32
33
34
35
36
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 32

def clone
  self.class.new(name, field: field, calendar_interval: calendar_interval, format: format).tap do |copy|
    copy.aggregations = aggregations.clone
  end
end

#to_h(&block) ⇒ Hash

Returns The Hash representation of the Aggregation. Properly formatted for Elasticsearch.

Returns:

  • (Hash)

    The Hash representation of the Aggregation. Properly formatted for Elasticsearch.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/date_histogram.rb', line 40

def to_h(&block)
  super do
    {
      date_histogram: {
        field: field,
        calendar_interval: calendar_interval,
        format: format
      }.compact
    }
  end
end