@@ -92,12 +92,11 @@ def __getitem__(self, n):
92
92
93
93
Slicing equates to the from/size parameters. E.g.::
94
94
95
- Search().query(...)[0:25]
95
+ s = Search().query(...)[0:25]
96
96
97
97
is equivalent to::
98
98
99
- {"query": ...
100
- "from": 0, "size": 25}
99
+ s = Search().query(...).extra(from_=0, size=25)
101
100
102
101
"""
103
102
s = self ._clone ()
@@ -130,6 +129,10 @@ def from_dict(cls, d):
130
129
return s
131
130
132
131
def _clone (self ):
132
+ """
133
+ Return a clone of the current search request. Performs a shallow copy
134
+ of all the underlying objects. Used internally by most state modifying APIs.
135
+ """
133
136
s = Search (using = self ._using , index = self ._index , doc_type = self ._doc_type )
134
137
s ._sort = self ._sort [:]
135
138
s ._extra = self ._extra .copy ()
@@ -143,6 +146,10 @@ def _clone(self):
143
146
return s
144
147
145
148
def update_from_dict (self , d ):
149
+ """
150
+ Apply options from a serialized body to the current instance. Modifies
151
+ the object in-place.
152
+ """
146
153
d = d .copy ()
147
154
self .query ._proxied = Q (d .pop ('query' ))
148
155
if 'post_filter' in d :
@@ -163,6 +170,10 @@ def update_from_dict(self, d):
163
170
self ._extra = d
164
171
165
172
def params (self , ** kwargs ):
173
+ """
174
+ Specify query params to be used when executing the search. All the
175
+ keyword arguments will override the current values.
176
+ """
166
177
s = self ._clone ()
167
178
s ._params .update (kwargs )
168
179
return s
@@ -181,13 +192,13 @@ def sort(self, *keys):
181
192
"""
182
193
Add sorting information to the search request. If called without
183
194
arguments it will remove all sort requirements. Otherwise it will
184
- replace them. Acceptable arguments are:
195
+ replace them. Acceptable arguments are::
185
196
186
197
'some.field'
187
198
'-some.other.fiels'
188
199
{'different.field': {'any': 'dict'}}
189
200
190
- so for example:
201
+ so for example::
191
202
192
203
s = Search().sort(
193
204
'category',
@@ -225,6 +236,11 @@ def index(self, *index):
225
236
return s
226
237
227
238
def doc_type (self , * doc_type ):
239
+ """
240
+ Set the type to search through. You can supply a single value or a
241
+ list. If no index is supplied (or an empty value) any information
242
+ stored on the instance will be erased.
243
+ """
228
244
# .doc_type() resets
229
245
s = self ._clone ()
230
246
if not doc_type :
@@ -233,7 +249,13 @@ def doc_type(self, *doc_type):
233
249
s ._doc_type = (self ._doc_type or []) + list (doc_type )
234
250
return s
235
251
236
- def to_dict (self , count = False , ** kwargs ):
252
+ def to_dict (self , count = False ):
253
+ """
254
+ Serialize the search into the dictionary that will be sent over as the request's body.
255
+
256
+ :arg count: a flag to specify we are interested in a body for count -
257
+ no aggregations, no pagination bounds etc.
258
+ """
237
259
if self .filter :
238
260
d = {
239
261
"query" : {
@@ -257,15 +279,24 @@ def to_dict(self, count=False, **kwargs):
257
279
258
280
if not count :
259
281
d .update (self ._extra )
260
- d .update (kwargs )
261
282
return d
262
283
263
284
def using (self , client ):
285
+ """
286
+ Associate the search request with an elasticsearch client. A fresh copy
287
+ will be returned with current instance remaining unchanged.
288
+
289
+ :arg client: and instance of ``elasticsearch.Elasticsearch`` to use
290
+ """
264
291
s = self ._clone ()
265
292
s ._using = client
266
293
return s
267
294
268
295
def count (self ):
296
+ """
297
+ Return the number of hits matching the query and filters. Note that
298
+ only the actual number is returned.
299
+ """
269
300
if not self ._using :
270
301
raise #XXX
271
302
@@ -278,6 +309,10 @@ def count(self):
278
309
)['count' ]
279
310
280
311
def execute (self ):
312
+ """
313
+ Execute the search and return an instance of ``Response`` wrapping all
314
+ the data.
315
+ """
281
316
if not self ._using :
282
317
raise #XXX
283
318
0 commit comments