Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::BucketSelector

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

Overview

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Constructor Details

#initialize(name, buckets_path:, script:, gap_policy: nil) ⇒ BucketSelector

Returns a new instance of BucketSelector.

Parameters:

  • name (String)

    The name used by Elasticsearch to identify the aggregation.

  • buckets_path (Hash)

    Path(s) to the metric or metrics over which the bucket_selector aggregation’s script will operate. The keys are the names of the script variables, the values the paths to the metrics (relative to the parent aggregation). The script will receive these variables in its params.

  • script (JayAPI::Elasticsearch::QueryBuilder::Script)

    Script used to decide whether to keep each bucket.

  • gap_policy (String, nil) (defaults to: nil)

    Optional gap policy (e.g. “skip”, “insert_zeros”).



26
27
28
29
30
31
32
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/bucket_selector.rb', line 26

def initialize(name, buckets_path:, script:, gap_policy: nil)
  super(name)

  @buckets_path = buckets_path
  @script       = script
  @gap_policy   = gap_policy
end

Instance Attribute Details

#buckets_pathObject (readonly)

Returns the value of attribute buckets_path.



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

def buckets_path
  @buckets_path
end

#gap_policyObject (readonly)

Returns the value of attribute gap_policy.



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

def gap_policy
  @gap_policy
end

#scriptObject (readonly)

Returns the value of attribute script.



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

def script
  @script
end

Instance Method Details

#aggsObject

Bucket selector is a pipeline agg and cannot have nested aggregations.



36
37
38
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/bucket_selector.rb', line 36

def aggs
  no_nested_aggregations('Bucket Selector')
end

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



41
42
43
44
45
46
47
48
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/bucket_selector.rb', line 41

def clone
  self.class.new(
    name,
    buckets_path: buckets_path.is_a?(Hash) ? buckets_path.dup : buckets_path,
    script:, # Script is immutable-ish, ok to reuse
    gap_policy:
  )
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.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/bucket_selector.rb', line 52

def to_h
  super do
    {
      bucket_selector: {
        buckets_path: buckets_path,
        script: script.to_h,
        gap_policy: gap_policy
      }.compact
    }
  end
end