Skip to content

Commit 7935741

Browse files
committed
[DSL] Add documentation for inner_hits search clause class
1 parent b187041 commit 7935741

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

lib/elasticsearch/dsl/search/inner_hits.rb

+75
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,81 @@ module Elasticsearch
1919
module DSL
2020
module Search
2121

22+
# Wraps the `inner_hits` part of a search definition
23+
#
24+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html
25+
#
2226
class InnerHits
2327
include BaseComponent
2428

29+
# Initialize the inner_hits definition.
30+
#
31+
# @param [ String, Symbol ] name The name to be used for the particular inner hit definition in the response.
32+
# Useful when multiple inner hits have been defined in a single search request. The default depends in which
33+
# query the inner hit is defined. For has_child query and filter this is the child type, has_parent query
34+
# and filter this is the parent type and the nested query and filter this is the nested path.
35+
#
36+
# @since 0.1.9
2537
def initialize(name, &block)
2638
@value = { name: name }
2739
super
2840
end
2941

42+
# Specify the size setting on the inner_hits definition, the maximum number of hits to return per inner_hits.
43+
# By default the top three matching hits are returned.
44+
#
45+
# @example
46+
# inner_hits 'last_tweet' do
47+
# size 10
48+
# from 5
49+
# end
50+
#
51+
# @param [ Integer ] size The size setting.
52+
#
53+
# @return self.
54+
#
55+
# @since 0.1.9
3056
def size(size)
3157
@value[:size] = size
58+
self
3259
end
3360

61+
# Specify the from setting on the inner_hits definition, the offset from where the first hit to fetch for
62+
# each inner_hits in the returned regular search hits.
63+
#
64+
# @example
65+
# inner_hits 'last_tweet' do
66+
# size 10
67+
# from 5
68+
# end
69+
#
70+
# @param [ Integer ] from The from setting.
71+
#
72+
# @return self.
73+
#
74+
# @since 0.1.9
3475
def from(from)
3576
@value[:from] = from
77+
self
3678
end
3779

80+
# Specify the sorting on the inner_hits definition. By default the hits are sorted by the score.
81+
#
82+
# @example
83+
# inner_hits 'last_tweet' do
84+
# size 10
85+
# from 5
86+
# sort do
87+
# by :date, order: 'desc'
88+
# by :likes, order: 'asc'
89+
# end
90+
# end
91+
#
92+
# @param [ Integer ] from The from setting.
93+
#
94+
# @return self.
95+
#
96+
# @since 0.1.9
3897
def sort(*args, &block)
3998
if !args.empty? || block
4099
@sort = Sort.new(*args, &block)
@@ -44,6 +103,22 @@ def sort(*args, &block)
44103
end
45104
end
46105

106+
# Convert the definition to a hash, to be used in a search request.
107+
#
108+
# @example
109+
# definition = begin do
110+
# inner_hits 'last_tweet' do
111+
# size 10
112+
# from 5
113+
# sort do
114+
# by :date, order: 'desc'
115+
# by :likes, order: 'asc'
116+
# end
117+
# end
118+
#
119+
# @return [ Hash ] The inner_hits clause as a hash.
120+
#
121+
# @since 0.1.9
47122
def to_hash
48123
call
49124
@hash = @value

0 commit comments

Comments
 (0)