這是正常的,彈性的搜索將不同的端口比你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`);
});