Elastic Search 将在与您的 Express 应用程序不同的端口上运行是正常的。事实上,您可以不让两台服务器在同一个端口上运行。
手电筒更像是一个不同的应用程序,您需要在服务器上运行它。使用npm start 或npm 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`);
});