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: https://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:, sort: nil, _source: nil) ⇒ TopHits

rubocop:disable-next Lint/UnderscorePrefixedVariableName -- to match Elasticsearch's name

Parameters:

  • name (String)

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

  • size (String)

    The number of hits that will be returned.

  • sort (Hash) (defaults to: nil)

    How to sort the documents to determine the top hits. When not specified the documents are sorted by the score of the main query.

  • _source (FalseClass, String, Array<String>, Hash) (defaults to: nil)

    Expression used for source filtering.

See Also:



32
33
34
35
36
37
38
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 32

def initialize(name, size:, sort: nil, _source: nil)
  super(name)

  @size = size
  @sort = sort
  @_source = _source
end

Instance Attribute Details

#_sourceObject (readonly)

Returns the value of attribute _source.



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

def _source
  @_source
end

#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

#sortObject (readonly)

Returns the value of attribute sort.



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

def sort
  @sort
end

Instance Method Details

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



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

def clone
  optional_params = { sort: sort.deep_dup, _source: _source.deep_dup }.compact
  copy = self.class.new(name, size: size, **optional_params)
  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.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/top_hits.rb', line 50

def to_h
  super do
    {
      top_hits: {
        size: size,
        sort: sort.deep_dup,
        _source: _source.deep_dup
      }.compact
    }
  end
end