それは弾性検索があなたのExpressアプリケーションとは別のポートで実行することが普通です。実際には、ではなく、同じポート上で2台のサーバーが稼働しているがあります。
懐中電灯は、あなたのサーバーで実行する必要がある別のアプリのようなものです。 npm start
またはnpm monitor
を使用すると、設定ファイルの設定後に懐中電灯プロセスを開始できます。懐中電灯は、FirebaseのデータをElastic Searchに持ってきてくれます。
Elastic Searchと対話するには、ノードモジュールを使用するだけです。あなたはすでにそれをしています。 Elastic Searchは前述のとおり9200
ポートで実行され、Expressアプリは別のポート(たとえば3000
)で実行されます。
懐中電灯に触発されたElasticfireには、懐中電灯にはない機能(例:結合)があり、アプリでライブラリとして使用できます。
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`);
});