【问题标题】:How to integrate Firebase Flashlight in my application如何在我的应用程序中集成 Firebase 手电筒
【发布时间】:2017-03-24 12:50:55
【问题描述】:

我正在尝试在我的 Node.js 应用程序中将 Firebase Flashlight 与 ElasticSearch 集成,以便对我的 Firebase 集合进行搜索操作。我想在api.js 中定义我的搜索路线(例如:myhost: myport/ search/mycollection/:key)。

问题在于myport 与运行 ElasticSearch 的那个不同(即 9200)。

我想在路线上:myhost: myport/whatever 运行我的应用程序,并在路线上myhost: myport/ search/mycollection/:key 上运行现在在myhost:9200 上可用的搜索。

如何将它们集成到 Express 中?

当我配置 ElasticSearch 时,我使用:

var config = {
      host: 'localhost',
      port: 9200,
      log: 'trace'
};
var esc = new ElasticSearch.Client(config);

【问题讨论】:

    标签: node.js elasticsearch firebase


    【解决方案1】:

    Elastic Search 将在与您的 Express 应用程序不同的端口上运行是正常的。事实上,您可以让两台服务器在同一个端口上运行。

    手电筒更像是一个不同的应用程序,您需要在服务器上运行它。使用npm startnpm monitor 可以在设置配置文件后启动Flashlight 进程。 Flashlight 会小心地将来自 Firebase 的数据带到 Elastic Search 中。

    要与 Elastic Search 交互,您只需使用 Node 模块。你已经这样做了。正如您所提到的,Elastic Search 将在端口 9200 上运行,而 Express 应用程序将在不同的端口上运行(例如 3000)。

    受 Flashlight 的启发,我创建了 Elasticfire,它具有 Flashlight 所没有的一些功能(例如连接),并且可以用作您应用中的库。

    const ElasticFire = require("elasticfire");
    
    // Initialize the ElasticFire instance
    let ef = new ElasticFire({
    
        // Set the Firebase configuration
        firebase: {
            apiKey: "AI...BY",
            authDomain: "em...d.firebaseapp.com",
            databaseURL: "https://em...d.firebaseio.com",
            storageBucket: "em...d.appspot.com",
            messagingSenderId: "95...36"
        }
    
        // Firebase paths and how to index them in Elasticsearch
      , paths: [
           {
               // Firebase path
               path : "articles"
    
               // Elasticsearch index and type
             , index: "articles"
             , type : "article"
    
               // Optional joined fields
             , joins: [
                   // The `author` is a field from the article
                   // which points to the `users` collection.
                   {
                       path: "users"
                     , name: "author"
                   }
    
                   // If we have an array of comment ids, pointing
                   // to another collection, then they will be joined too
                 , {
                       path: "comments"
                     , name: "comments"
                   }
               ]
    
               // Filter out some data
             , filter: (data, snap) => snap.key !== "_id"
           }
        ]
    });
    
    // Listen for the events emitted by
    // the ElasticFire instanceand output some data
    ef.on("error", err => {
        console.error(err);
    }).on("index_created", name => {
        console.log(`${name} created`);
    }).on("index_updated", name => {
        console.log(`${name} updated`);
    }).on("index_deleted", name => {
        console.log(`${name} deleted`);
    });
    

    【讨论】:

      猜你喜欢
      • 2014-06-17
      • 1970-01-01
      • 2012-01-15
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多