这是正常的,弹性的搜索将不同的端口比你Express应用程序上运行。实际上,您可以在而不是的两台服务器上运行相同的端口。
手电筒更像是一个不同的应用程序,您需要在您的服务器上运行。使用npm start
或npm 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`);
});