Class: Elastic::Datatypes::Time

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

Constant Summary

Constants inherited from Default

Default::MAPPING_OPTIONS

Instance Method Summary collapse

Methods inherited from Default

#histogram_aggregation_defaults, #initialize, #match_query_defaults, #prepare_for_index, #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



25
26
27
# File 'lib/elastic/datatypes/time.rb', line 25

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

#mapping_optionsObject



3
4
5
6
7
# File 'lib/elastic/datatypes/time.rb', line 3

def mapping_options
  options = super
  options[:type] = 'date'
  options
end

#prepare_value_for_result(_value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/elastic/datatypes/time.rb', line 9

def prepare_value_for_result(_value)
  # TODO: set timezone
  case _value
  when ::String
    time_zone.parse(_value)
  when ::Integer
    time_zone.at(_value / 1000)
  else
    _value
  end
end

#supported_aggregationsObject



21
22
23
# File 'lib/elastic/datatypes/time.rb', line 21

def supported_aggregations
  [:date_histogram] + super
end