Node.js 如何在我的应用程序中集成Firebase手电筒
我正试图在Node.js应用程序中与ElasticSearch集成,以便对我的Firebase集合进行搜索操作。我想在Node.js 如何在我的应用程序中集成Firebase手电筒,node.js,
elasticsearch,firebase,Node.js,
elasticsearch,Firebase,我正试图在Node.js应用程序中与ElasticSearch集成,以便对我的Firebase集合进行搜索操作。我想在api.js中定义我的搜索路径(例如:myhost:myport/search/mycollection/:key) 问题在于myport与运行ElasticSearch的端口(9200)不同 我想在route:myhost:myport/whatever上运行我的应用程序,并在routemyhost:myport/search/mycollection/:key上运行搜索,该搜
api.js
中定义我的搜索路径(例如:myhost:myport/search/mycollection/:key
)
问题在于myport
与运行ElasticSearch的端口(9200)不同
我想在route:myhost:myport/whatever
上运行我的应用程序,并在routemyhost:myport/search/mycollection/:key
上运行搜索,该搜索现在可在myhost:9200
上使用
如何将它们集成到Express中
配置ElasticSearch时,我使用:
var config = {
host: 'localhost',
port: 9200,
log: 'trace'
};
var esc = new ElasticSearch.Client(config);
弹性搜索将在与Express应用程序不同的端口上运行是正常的。事实上,不能在同一端口上运行两台服务器 手电筒更像是一个不同的应用程序,你需要在你的服务器上运行。使用
npm start
或npm monitor
可以在设置配置文件后启动手电筒过程。在弹性搜索中,手电筒将为您带来Firebase的数据
要与弹性搜索交互,只需使用节点模块。你已经这么做了。弹性搜索将在您提到的端口9200
上运行,而Express应用程序将在不同的端口上运行(例如3000
)
受Flashlight的启发,我创建了一个Flashlight,它有一些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`);
});