File tree 4 files changed +66
-0
lines changed
4 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,15 @@ class Document
250
250
# ex: query = Document.where('field', '==': 'value')
251
251
```
252
252
``` coffee
253
+ @ refresh = (args ) ->
254
+ ###
255
+ Explicitly refresh one or more index.
256
+ https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
257
+ @params args {object}
258
+ @returns {promise}
259
+ ###
260
+ ```
261
+ ``` coffee
253
262
@ updateMapping = ->
254
263
###
255
264
Update the index mapping.
Original file line number Diff line number Diff line change 282
282
return query . intersect ( field , operation ) ;
283
283
} ;
284
284
285
+ Document . refresh = function ( args ) {
286
+ var deferred ;
287
+ if ( args == null ) {
288
+ args = { } ;
289
+ }
290
+
291
+ /*
292
+ Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
293
+ https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
294
+ @params args {object}
295
+ @returns {promise }
296
+ */
297
+ deferred = q . defer ( ) ;
298
+ args . index = this . getIndexName ( ) ;
299
+ this . _es . indices . refresh ( args , function ( error ) {
300
+ if ( error ) {
301
+ deferred . reject ( error ) ;
302
+ return ;
303
+ }
304
+ return deferred . resolve ( ) ;
305
+ } ) ;
306
+ return deferred . promise ;
307
+ } ;
308
+
285
309
Document . updateMapping = function ( ) {
286
310
287
311
/*
Original file line number Diff line number Diff line change @@ -199,6 +199,22 @@ module.exports = class Document
199
199
query = new Query (@ )
200
200
query .intersect field, operation
201
201
202
+ @ refresh = (args = {}) ->
203
+ ###
204
+ Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
205
+ https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
206
+ @params args {object}
207
+ @returns {promise}
208
+ ###
209
+ deferred = q .defer ()
210
+ args .index = @ getIndexName ()
211
+ @_es .indices .refresh args, (error ) ->
212
+ if error
213
+ deferred .reject error
214
+ return
215
+ deferred .resolve ()
216
+ deferred .promise
217
+
202
218
@ updateMapping = ->
203
219
###
204
220
Update the index mapping.
Original file line number Diff line number Diff line change @@ -200,6 +200,23 @@ exports.testDocumentAll = (test) ->
200
200
test .equal query .documentClass , DataModel
201
201
test .done ()
202
202
203
+ exports .testDocumentRefresh = (test ) ->
204
+ class DataModel extends Document
205
+ @_index = ' index'
206
+ _es = DataModel ._es
207
+ DataModel ._es =
208
+ indices :
209
+ refresh : (args , callback ) ->
210
+ test .deepEqual args,
211
+ index : ' index'
212
+ callback null , yes
213
+
214
+ test .expect 2
215
+ DataModel .refresh ().then ->
216
+ test .ok 1
217
+ test .done ()
218
+ DataModel ._es = _es
219
+
203
220
exports .testDocumentWhere = (test ) ->
204
221
class DataModel extends Document
205
222
@_index = ' index'
You can’t perform that action at this time.
0 commit comments