Class: ElasticsearchDslBuilder::DSL::Search::InnerHits
- Inherits:
-
Object
- Object
- ElasticsearchDslBuilder::DSL::Search::InnerHits
- Defined in:
- lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb
Instance Method Summary collapse
- #exclude_fields(*fields) ⇒ Object
- #from(value) ⇒ Object
- #include_fields(*fields) ⇒ Object
- #size(value) ⇒ Object
- #sort_by(name, direction = nil) ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#exclude_fields(*fields) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 32 def exclude_fields(*fields) fields = fields.flatten fields_valid = !fields.empty? && fields.all? { |f| f.instance_of?(String) } raise ArgumentError, 'must pass at least 1 String field' unless fields_valid @excluded_fields ||= [] @excluded_fields.concat fields self end |
#from(value) ⇒ Object
11 12 13 14 15 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 11 def from(value) raise ArgumentError, 'value must be Numeric' unless value.is_a? Numeric @from = value self end |
#include_fields(*fields) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 23 def include_fields(*fields) fields = fields.flatten fields_valid = !fields.empty? && fields.all? { |f| f.instance_of?(String) } raise ArgumentError, 'must pass at least 1 String field' unless fields_valid @included_fields ||= [] @included_fields.concat fields self end |
#size(value) ⇒ Object
5 6 7 8 9 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 5 def size(value) raise ArgumentError, 'value must be Numeric' unless value.is_a? Numeric @size = value self end |
#sort_by(name, direction = nil) ⇒ Object
17 18 19 20 21 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 17 def sort_by(name, direction = nil) @sort ||= Sort.new @sort.by(name, direction) self end |
#to_hash ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/inner_hits.rb', line 41 def to_hash hash = {} hash.update(sort: @sort.to_hash) if @sort hash.update(size: @size) if @size hash.update(from: @from) if @from unless @included_fields.to_a.empty? && @excluded_fields.to_a.empty? source = {} source.update(includes: @included_fields) unless @included_fields.to_a.empty? source.update(excludes: @excluded_fields) unless @excluded_fields.to_a.empty? hash.update(_source: source) end hash end |