Class: ElasticsearchDslBuilder::DSL::Search::Aggregations::Stats

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

Instance Method Summary collapse

Methods inherited from Aggregation

#aggregation

Constructor Details

#initializeStats

Returns a new instance of Stats.



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

def initialize
  @type = :stats
  super()
end

Instance Method Details

#field(field) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb', line 11

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

#missing(missing) ⇒ Object



23
24
25
26
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb', line 23

def missing(missing)
  @missing = missing
  self
end

#script(script) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb', line 17

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

#to_hashObject

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/stats.rb', line 28

def to_hash
  raise ArgumentError, 'must have set at least one of [field, script]' if @field.nil? && @script.nil?
  @aggregation = {}
  @aggregation.update(field: @field) if @field
  @aggregation.update(script: @script.to_hash) if @script
  @aggregation.update(missing: @missing) if @missing
  super
end