2016-11-10 7 views
1

Firebaseコレクションの検索操作を行うために、Node.jsアプリケーションでFirebase FlashlightとElasticSearchを統合しようとしています。 api.jsで検索ルートを定義する場所を指定します(例:myhost: myport/ search/mycollection/:key)。Firebaseの懐中電灯をアプリケーションに統合する方法

問題は、myportは、ElasticSearchが実行されているもの(9200)とは異なることです。

私のアプリを実行するにはmyhost: myport/whatever、ルートをmyhost: myport/ search/mycollection/:keyにしてください。myhost:9200で利用可能な検索を実行してください。

Expressにどのように統合できますか?

私はElasticSearchをconfigの場合は、私が使用:

var config = { 
     host: 'localhost', 
     port: 9200, 
     log: 'trace' 
}; 
var esc = new ElasticSearch.Client(config); 

答えて

1

それは弾性検索があなたの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`); 
}); 
関連する問題