Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::TopHits

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

Overview

Represents a filter aggregation in Elasticsearch. Information on this type of aggregation can be found here: www.elastic.co/docs/reference/aggregations/search-aggregations-metrics-top-hits-aggregation

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Methods inherited from Aggregation

#aggs

Constructor Details

#initialize(name, size:) ⇒ TopHits

Returns a new instance of TopHits.

Parameters:

  • name (String)

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

  • size (String)

    The number of hits that will be returned.



23
24
25
26
27
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 23

def initialize(name, size:)
  super(name)

  @size = size
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



18
19
20
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 18

def size
  @size
end

Instance Method Details

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



30
31
32
33
34
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 30

def clone
  copy = self.class.new(name, size: size)
  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.



38
39
40
41
42
43
44
45
46
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 38

def to_h
  super do
    {
      top_hits: {
        size: size
      }
    }
  end
end