本文介绍了在ElasticSearch Bonsai Free Instance中,如何使用Firebase FlashLight对每个对象进行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢FlashLight 的教程,这个但是,如果您保留免费的ES实例,则在并发访问方面是有限的,当您启动您的节点时应用程序,您在日志中看到以下消息:

如何解决?

解决方案

如果您有一堆索引数据,Flashlight应用程序将要求ES在运行时对每个对象进行索引,而无需任何资源访问约束。您必须使用信号量来控制/限制访问此共享资源。



安装信号量库

  npm我 - 保存信号量

编辑 PathMonitor.js 文件,并将访问ES资源限制为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错误,响应);
}
} .bind(that));
});
},
...
}

在付款计划的情况下需要。


Thanks to the tutorial of the FlashLight https://github.com/firebase/flashlight, this is somehow easy to do fulltextsearch with Firebase.

However, if you keep the free ES instance, it is limited in term of concurrency access, and when you will start your node app, you see the following message in the log :

How to solve this ?

解决方案

If you have a bunch of data to index, the Flashlight app will ask ES to index every object on the fly, without any resource access constraint. You have to control/limit the access this share resource with a Semaphore.

Install the Semaphore lib

npm i --save semaphore

Edit the PathMonitor.js file, and limit access to ES resource to 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));
        });
    },
    ...
}

This may not be required in case of paid plan.

这篇关于在ElasticSearch Bonsai Free Instance中,如何使用Firebase FlashLight对每个对象进行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:46