Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::ScriptedMetric

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

Overview

Represents a scripted_metric aggregation in Elasticsearch. Information about this type of aggregation can be found in: www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Constructor Details

#initialize(name, map_script:, combine_script:, reduce_script:, init_script: nil) ⇒ ScriptedMetric

Returns a new instance of ScriptedMetric.

Parameters:

  • name (String)

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

  • init_script (String) (defaults to: nil)

    The script that gets executed prior to any collection of documents. Allows the aggregation to set up any initial state.

  • map_script (String)

    The script that gets executed once per document collected. This is a required script.

  • combine_script (String)

    The script that gets executed once on each shard after document collection is complete. Allows the aggregation to consolidate the state returned from each shard.

  • reduce_script (String)

    The script that gets executed once on the coordinating node after all shards have returned their results. The script is provided with access to a variable states which is an array of the result of the combine_script on each shard.



30
31
32
33
34
35
36
37
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 30

def initialize(name, map_script:, combine_script:, reduce_script:, init_script: nil)
  super(name)

  @init_script = init_script
  @map_script = map_script
  @combine_script = combine_script
  @reduce_script = reduce_script
end

Instance Attribute Details

#combine_scriptObject (readonly)

Returns the value of attribute combine_script.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 13

def combine_script
  @combine_script
end

#init_scriptObject (readonly)

Returns the value of attribute init_script.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 13

def init_script
  @init_script
end

#map_scriptObject (readonly)

Returns the value of attribute map_script.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 13

def map_script
  @map_script
end

#reduce_scriptObject (readonly)

Returns the value of attribute reduce_script.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 13

def reduce_script
  @reduce_script
end

Instance Method Details

#aggsObject

Raises:



42
43
44
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 42

def aggs
  no_nested_aggregations('Scripted Metric')
end

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



47
48
49
50
51
52
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 47

def clone
  self.class.new(
    name, map_script: map_script, combine_script: combine_script,
          reduce_script: reduce_script, init_script: init_script
  )
end

#to_hHash

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

Returns:

  • (Hash)

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



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/scripted_metric.rb', line 56

def to_h
  super do
    {
      scripted_metric: {
        init_script: init_script,
        map_script: map_script,
        combine_script: combine_script,
        reduce_script: reduce_script
      }.compact
    }
  end
end