Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sources::Terms

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

Overview

Represents a “Terms” value source for a Composite aggregation. More information about this type of value source can be found here: www.elastic.co/docs/reference/aggregations/search-aggregations-bucket-composite-aggregation#_terms

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, field:, order: nil, missing_bucket: nil, missing_order: nil) ⇒ Terms

Returns a new instance of Terms.

Parameters:

  • name (String)

    The name for the value source.

  • field (String)

    The field for the value source.

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

    The order in which the values coming from this data source should be ordered, this can be either “asc” or “desc”

  • missing_bucket (Boolean) (defaults to: nil)

    Whether or not a bucket for the documents without a value in field should be created.

  • missing_order (String) (defaults to: nil)

    Where to put the bucket for the documents with a missing value, either “first” or “last”.



23
24
25
26
27
28
29
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 23

def initialize(name, field:, order: nil, missing_bucket: nil, missing_order: nil)
  @name = name
  @field = field
  @order = order
  @missing_bucket = missing_bucket
  @missing_order = missing_order
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



12
13
14
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 12

def field
  @field
end

#missing_bucketObject (readonly)

Returns the value of attribute missing_bucket.



12
13
14
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 12

def missing_bucket
  @missing_bucket
end

#missing_orderObject (readonly)

Returns the value of attribute missing_order.



12
13
14
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 12

def missing_order
  @missing_order
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 12

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



12
13
14
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 12

def order
  @order
end

Instance Method Details

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



32
33
34
35
36
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 32

def clone
  self.class.new(
    name, field: field, order: order, missing_bucket: missing_bucket, missing_order: missing_order
  )
end

#to_hHash

Returns The hash representation for the value source.

Returns:

  • (Hash)

    The hash representation for the value source.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sources/terms.rb', line 39

def to_h
  {
    name => {
      terms: {
        field: field,
        order: order,
        missing_bucket: missing_bucket,
        missing_order: missing_order
      }.compact
    }
  }
end