Class: Elasticsearch::DSL::Search::Aggregations::ScriptedMetric

Inherits:
Object
  • Object
show all
Includes:
BaseComponent
Defined in:
lib/elasticsearch/dsl/search/aggregations/scripted_metric.rb

Overview

A metric aggregation which uses scripts for the computation

See the integration test for a full example.

Examples:


search do
  aggregation :clicks_for_one do
    scripted_metric do
      init_script "_agg['transactions'] = []"
      map_script  "if (doc['tags'].value.contains('one')) { _agg.transactions.add(doc['clicks'].value) }"
      combine_script "sum = 0; for (t in _agg.transactions) { sum += t }; return sum"
      reduce_script "sum = 0; for (a in _aggs) { sum += a }; return sum"
    end
  end
end

See Also:

Method Summary

Methods included from BaseComponent

included, #initialize