Skip to content

Commit 5a8d716

Browse files
committed
Support refresh().
1 parent 1f34ebd commit 5a8d716

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ class Document
250250
# ex: query = Document.where('field', '==': 'value')
251251
```
252252
```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
253262
@updateMapping = ->
254263
###
255264
Update the index mapping.

lib/document.js

+24
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,30 @@
282282
return query.intersect(field, operation);
283283
};
284284

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+
285309
Document.updateMapping = function() {
286310

287311
/*

src/lib/document.coffee

+16
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ module.exports = class Document
199199
query = new Query(@)
200200
query.intersect field, operation
201201

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+
202218
@updateMapping = ->
203219
###
204220
Update the index mapping.

tests/test-document.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ exports.testDocumentAll = (test) ->
200200
test.equal query.documentClass, DataModel
201201
test.done()
202202

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+
203220
exports.testDocumentWhere = (test) ->
204221
class DataModel extends Document
205222
@_index = 'index'

0 commit comments

Comments
 (0)