2016-05-26 9 views
5

FlashLight https://github.com/firebase/flashlightのチュートリアルのおかげで、Firebaseでフルテキスト検索を行うのは簡単です。ElasticSearch Bonsai Free InstanceでFirebase FlashLightを使ってオブジェクトごとにインデックスを作成する方法

しかし、あなたが自由ESのインスタンスを続ければ、それは同時実行のアクセスの期間中に限られており、あなたはノードアプリを起動しますとき、あなたはログに次のメッセージを参照してください。

failed to index firebase/xxx/-KHLhdwGplb3lHWjm8RS: Error: Concurrent request limit exceeded. Please consider batching your requests, or contact [email protected] for help.

どのようにしこれを解決する?

答えて

9

インデックスを作成するデータがたくさんある場合、懐中電灯アプリは、リソースアクセスの制約なしで、ESにすべてのオブジェクトをオンザフライでインデックスするようにESに指示します。この共有リソースへのアクセスをセマフォで制御/制限する必要があります。

npm i --save semaphore 

編集libにPathMonitor.jsファイルをセマフォをインストールし、そしてこれは、有料プランの場合に必要とされないことが1

PathMonitor.prototype = { 
    _init: function() { 
     this.sem = require('semaphore')(1); 
     this.addMonitor = this.ref.on('child_added', this._process.bind(this, this._childAdded)); 
     this.changeMonitor = this.ref.on('child_changed', this._process.bind(this, this._childChanged)); 
     this.removeMonitor = this.ref.on('child_removed', this._process.bind(this, this._childRemoved)); 
    }, 
    ... 
    _index: function (key, data, callback) { 
     var that = this; 
     that.sem.take(function() { 
      that.esc.index({ 
       index: that.index, 
       type : that.type, 
       id : key, 
       body : data 
      }, function (error, response) { 
       that.sem.leave(); 
       if (callback) { 
        callback(error, response); 
       } 
      }.bind(that)); 
     }); 
    }, 
    ... 
} 

にESリソースへのアクセスを制限します。

+0

これは素晴らしい機能です。ありがとう! – Simon

+0

@Anthony:私はあなたの提案をしましたが、私はまだ同じエラーがあります –

関連する問題