|
|
@@ -210,15 +210,33 @@ SearchClient.prototype.addAllPages = function()
|
|
|
var Page = this.crowi.model('Page');
|
|
|
var cursor = Page.getStreamOfFindAll();
|
|
|
var body = [];
|
|
|
+ var sent = 0;
|
|
|
+ var skipped = 0;
|
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
cursor.on('data', function (doc) {
|
|
|
if (!doc.creator || !doc.revision || !self.shouldIndexed(doc)) {
|
|
|
- debug('Skipped', doc.path);
|
|
|
+ //debug('Skipped', doc.path);
|
|
|
+ skipped++;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
self.prepareBodyForCreate(body, doc);
|
|
|
+ //debug(body.length);
|
|
|
+ if (body.length > 2000) {
|
|
|
+ sent++;
|
|
|
+ debug('Sending request (seq, skipped)', sent, skipped);
|
|
|
+ self.client.bulk({
|
|
|
+ body: body,
|
|
|
+ requestTimeout: Infinity,
|
|
|
+ }).then(res => {
|
|
|
+ debug('addAllPages add anyway (items, errors, took): ', (res.items || []).length, res.errors, res.took)
|
|
|
+ }).catch(err => {
|
|
|
+ debug('addAllPages error on add anyway: ', err)
|
|
|
+ });
|
|
|
+
|
|
|
+ body = [];
|
|
|
+ }
|
|
|
}).on('error', function (err) {
|
|
|
// TODO: handle err
|
|
|
debug('Error cursor:', err);
|
|
|
@@ -231,13 +249,13 @@ SearchClient.prototype.addAllPages = function()
|
|
|
return resolve();
|
|
|
}
|
|
|
|
|
|
- // 最後に送信
|
|
|
+ // 最後にすべてを送信
|
|
|
self.client.bulk({
|
|
|
body: body,
|
|
|
requestTimeout: Infinity,
|
|
|
})
|
|
|
.then(function(res) {
|
|
|
- debug('Reponse from es:', res);
|
|
|
+ debug('Reponse from es (item length, errros, took):', (res.items || []).length, res.errors, res.took);
|
|
|
return resolve(res);
|
|
|
}).catch(function(err) {
|
|
|
debug('Err from es:', err);
|