Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Filter

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

Overview

Represents a filter aggregation in Elasticsearch. Information on this type of aggregation can be found here: www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html

Instance Attribute Summary

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Methods inherited from Aggregation

#aggs

Constructor Details

#initialize(name) {|The| ... } ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • name (String)

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

Yield Parameters:



22
23
24
25
26
27
28
29
30
31
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/filter.rb', line 22

def initialize(name, &block)
  super(name)

  unless block
    raise(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Errors::AggregationsError,
          "The #{self.class.name.demodulize} aggregation must be initialized with a block")
  end

  block.call(query)
end

Instance Method Details

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



34
35
36
37
38
39
40
41
42
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/filter.rb', line 34

def clone
  # rubocop:disable Lint/EmptyBlock (The query will be assigned later)
  copy = self.class.new(name) {}
  # rubocop:enable Lint/EmptyBlock

  copy.query = query.clone
  copy.aggregations = aggregations.clone
  copy
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.



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

def to_h
  super do
    {
      filter: query.to_h
    }
  end
end