2016-11-10 30 views
1

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

问题是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); 

回答

1

这是正常的,弹性的搜索将不同的端口比你Express应用程序上运行。实际上,您可以在而不是的两台服务器上运行相同的端口。

手电筒更像是一个不同的应用程序,您需要在您的服务器上运行。使用npm startnpm monitor您可以在设置配置文件后启动手电筒过程。 Flashlight将小心为您提供Firebase中的弹性搜索数据。

要与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`); 
}); 
相关问题