我正在编写服务器代码,用于侦听firebase数据库上的搜索请求并返回搜索结果。这是将Firebase数据库中的数据编入索引到Elastic Search的代码。这是索引数据的正确方法吗?
var firebase = require('firebase');
var ElasticClient = require('elasticsearchclient');
// listen for changes to Firebase data
var client = new ElasticClient({host:'localhost',port:9200});
firebase.initializeApp({
serviceAccount: {
...
},
databaseURL: "https://searchserver.firebaseio.com/"
})
var db = firebase.database();
var ref = db.ref("realtime");
ref.on('child_added', upsert);
ref.on('child_changed', upsert);
ref.on('child_removed', remove);
function upsert(snap) {
client.index({
index: 'firebase',
type: 'users',
id: snap.key,
body: snap.val()
}, function (err, response) {
if (err) {
console.log("error indexing " + error)
}
});
}
function remove(snap) {
client.delete({
index: 'firebase',
type: 'users',
id: snap.key
}, function (error, response) {
if (error) {
console.log("Error deleting user : " + error);
}
});
}
这是错误消息。
TypeError: Request path contains unescaped characters.
at new ClientRequest (_http_client.js:50:11)
at Object.exports.request (http.js:31:10)
at ElasticSearchCall.exec (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\elasticsearchclient\lib\elasticsearchclient\calls\elasticSearchCall.js:45:26)
at ElasticSearchClient.createCall (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\elasticsearchclient\lib\elasticsearchclient\elasticSearchClient.js:28:14)
at ElasticSearchClient.index (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\elasticsearchclient\lib\elasticsearchclient\calls\core.js:37:17)
at upsert (C:\Users\jojo\Documents\readouts-search\readouts-server\readouts-server.js:28:12)
at C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\firebase\database-node.js:146:375
at Qb (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\firebase\database-node.js:43:165)
at nc (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\firebase\database-node.js:31:216)
at oc (C:\Users\jojo\Documents\readouts-search\readouts-server\node_modules\firebase\database-node.js:30:701)
snap.val()的值
{ '5Nyu7Px7vNYGizJqlyGHhAfnvwu2':
{ allOwnerVideos: 'none',
allRatedVideos: 'none',
email: 'iron@man.com',
favorite_category:
{ fifth: 'Business',
first: 'Sports',
fourth: 'Biography',
second: 'Sci-Fi',
seventh: 'Action and Adventure',
sixth: 'Art',
third: 'Satire' },
name: 'iron',
personalmessage: 'man',
profileimage: 'https://firebasestorage.googleapis.com/v0/b/readoutsa75e0.appspot.com/o/ProfilePictures%2F_5Nyu7Px7vNYGizJqlyGHhAfnvwu2.jpg?alt=media&token=743dbd6a-985c-4481-9d63-4ed30e8703a9' },
'6bt3EqdWyfQ3ksEdy9BTyYvQK4F3'