Class: ElasticsearchDslBuilder::DSL::Search::Aggregations::Terms
- Inherits:
-
Aggregation
- Object
- Aggregation
- ElasticsearchDslBuilder::DSL::Search::Aggregations::Terms
- Defined in:
- lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb
Instance Method Summary collapse
- #exclude(exclude) ⇒ Object
- #field(field) ⇒ Object
- #include(include) ⇒ Object
-
#initialize ⇒ Terms
constructor
A new instance of Terms.
- #script(script) ⇒ Object
- #size(size) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Aggregation
Constructor Details
#initialize ⇒ Terms
Returns a new instance of Terms.
6 7 8 9 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 6 def initialize @type = :terms super() end |
Instance Method Details
#exclude(exclude) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 37 def exclude(exclude) exclude_valid = exclude.instance_of?(String) || (exclude.instance_of?(Array) && exclude.all? { |i| i.instance_of?(String) }) raise ArgumentError, 'exclude argument must be a String or Array of Strings' unless exclude_valid @exclude = exclude self end |
#field(field) ⇒ Object
11 12 13 14 15 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 11 def field(field) raise ArgumentError, 'field must be a String' unless field.instance_of?(String) @field = field self end |
#include(include) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 29 def include(include) include_valid = include.instance_of?(String) || (include.instance_of?(Array) && include.all? { |i| i.instance_of?(String) }) raise ArgumentError, 'include argument must be a String or Array of Strings' unless include_valid @include = include self end |
#script(script) ⇒ Object
17 18 19 20 21 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 17 def script(script) raise ArgumentError, 'script must be a Script' unless script.instance_of?(Script) @script = script self end |
#size(size) ⇒ Object
23 24 25 26 27 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 23 def size(size) raise ArgumentError, 'size must be Numeric' unless size.is_a?(Numeric) @size = size self end |
#to_hash ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregations/terms.rb', line 45 def to_hash raise ArgumentError, 'must have set at least one of [field, script]' if @field.nil? && @script.nil? @aggregation = {} @aggregation.update(field: @field) if @field @aggregation.update(script: @script.to_hash) if @script @aggregation.update(size: @size) if @size @aggregation.update(include: @include) if @include @aggregation.update(exclude: @exclude) if @exclude super end |