Class: Elastic::Datatypes::Date

Inherits:
Default
  • Object
show all
Defined in:
lib/elastic/datatypes/date.rb

Constant Summary

Constants inherited from Default

Elastic::Datatypes::Default::MAPPING_OPTIONS

Instance Method Summary collapse

Methods inherited from Default

#histogram_aggregation_defaults, #initialize, #mapping_options, #match_query_defaults, #prepare_for_query, #range_aggregation_defaults, #range_query_defaults, #supported_queries, #term_query_defaults, #terms_aggregation_defaults

Constructor Details

This class inherits a constructor from Elastic::Datatypes::Default

Instance Method Details

#date_histogram_aggregation_defaultsObject



28
29
30
# File 'lib/elastic/datatypes/date.rb', line 28

def date_histogram_aggregation_defaults
  { interval: '1w', time_zone: time_zone }
end

#prepare_for_index(_value) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/elastic/datatypes/date.rb', line 3

def prepare_for_index(_value)
  if !_value.nil? && !_value.is_a?(::Date)
    raise ArgumentError, "expected a date for field #{name}"
  end

  # date is stored as the corresponding utc timestamp in elastic search,
  # no need to convert it here
  _value
end

#prepare_value_for_result(_value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/elastic/datatypes/date.rb', line 13

def prepare_value_for_result(_value)
  case _value
  when ::String
    time_zone.parse(_value).to_date
  when ::Integer
    time_zone.at(_value / 1000).to_date
  else
    _value
  end
end

#supported_aggregationsObject



24
25
26
# File 'lib/elastic/datatypes/date.rb', line 24

def supported_aggregations
  [:date_histogram] + super
end