class Elasticsearch::DSL::Search::Queries::InnerHits
Wraps the `inner_hits` part of a search definition
@see www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
Public Class Methods
Initialize the inner_hits definition.
@param [ String, Symbol ] name The name to be used for the particular inner hit definition in the response.
Useful when multiple inner hits have been defined in a single search request. The default depends in which query the inner hit is defined. For has_child query and filter this is the child type, has_parent query and filter this is the parent type and the nested query and filter this is the nested path.
@since 0.1.9
Elasticsearch::DSL::Search::BaseComponent::new
# File lib/elasticsearch/dsl/search/queries/inner_hits.rb, line 38 def initialize(name=nil, &block) @value = name ? { name: name } : {} super end
Public Instance Methods
Specify the from setting on the inner_hits definition, the offset from where the first hit to fetch for
each inner_hits in the returned regular search hits.
@example
inner_hits 'last_tweet' do size 10 from 5 end
@param [ Integer ] from The from setting.
@return self.
@since 0.1.9
# File lib/elasticsearch/dsl/search/queries/inner_hits.rb, line 76 def from(from) @value[:from] = from self end
Specify the size setting on the inner_hits definition, the maximum number of hits to return per inner_hits.
By default the top three matching hits are returned.
@example
inner_hits 'last_tweet' do size 10 from 5 end
@param [ Integer ] size The size setting.
@return self.
@since 0.1.9
# File lib/elasticsearch/dsl/search/queries/inner_hits.rb, line 57 def size(size) @value[:size] = size self end
Specify the sorting on the inner_hits definition. By default the hits are sorted by the score.
@example
inner_hits 'last_tweet' do size 10 from 5 sort do by :date, order: 'desc' by :likes, order: 'asc' end end
@param [ Integer ] from The from setting.
@return self.
@since 0.1.9
# File lib/elasticsearch/dsl/search/queries/inner_hits.rb, line 98 def sort(*args, &block) if !args.empty? || block @sort = Sort.new(*args, &block) self else @sort end end
Convert the definition to a hash, to be used in a search request.
@example
definition = begin do inner_hits 'last_tweet' do size 10 from 5 sort do by :date, order: 'desc' by :likes, order: 'asc' end end
@return [ Hash ] The inner_hits clause as a hash.
@since 0.1.9
# File lib/elasticsearch/dsl/search/queries/inner_hits.rb, line 123 def to_hash call @hash = @value @hash[:sort] = @sort.to_hash if @sort @hash end