无法使用Firebase和ElasticSearch(使用手电筒)进行正确的path监控或查询

我正在尝试整合ElasticSearch和Firebase。 我正在使用来自Firebase的Flashlight集成来完成所有工作。 我已经将代码部署到了Heroku,如上面链接的Github repo中所述。

它的工作原理是当我插入查询objet到/search/request/我得到一个/search/response结果。 但结果有点乱,不正确。 但我无法弄清楚什么是错的。

这是config.js中定义要监视的path的内容:

 /** Paths to Monitor * * Each path can have these keys: * {string} path: [required] the Firebase path to be monitored, for example, `users/profiles` * would monitor https://<instance>.firebaseio.com/users/profiles * {string} index: [required] the name of the ES index to write data into * {string} type: [required] name of the ES object type this document will be stored as * {Array} fields: list of fields to be monitored and indexed (defaults to all fields, ignored if "parser" is specified) * {Array} omit: list of fields that should not be indexed in ES (ignored if "parser" is specified) * {Function} filter: if provided, only records that return true are indexed * {Function} parser: if provided, the results of this function are passed to ES, rather than the raw data (fields is ignored if this is used) * * To store your paths dynamically, rather than specifying them all here, you can store them in Firebase. * Format each path object with the same keys described above, and store the array of paths at whatever * location you specified in the FB_PATHS variable. Be sure to restrict that data in your Security Rules. ****************************************************/ exports.paths = [{ path: "users", index: "firebase", type: "user" }, { path: "messages", index: "firebase", type: "message", fields: ['msg', 'name'], filter: function(data) { return data.name !== 'system'; } }]; 

这是Firebase中用户节点的结构(位于根目录)。

 "users" : { "userid123" : { "friends" : { "userid42" : 1 }, "recs" : { "-recid1234" : 0 }, "user_info" : { "createdAt" : 1475157596, "email" : "e@male.org", "name" : "Firstname Lastname Johnson", "profilePicture" : "png.jpg", "pushId" : { }, "username" : "userLooser" } }, "userid42" : { "friends" : { "userid123" : 1, "test1" : 1 }, "recs" : { "-recid5678" : 0 }, "user_info" : { "email" : "email@icloud.com", "name" : "Firstname Lastname", "phoneNumber" : "", "profilePicture" : "jpg.png", "pushId" : { }, "username" : "userName" } } } } 

我想要实现的是search用户名,并返回最佳结果。 我真正需要的是用户名和用户名。

Firebase搜索查询的图像

但是,当我查询上面的图像中的对象时,我得到了下面的答案:

  "search" : { "response" : { "index" : { ".priority" : 1.477326417519E12, "hits" : [ { "_id" : "test1", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { "test1" : 1 }, "recs" : { }, "user_info" : { "createdAt" : 1475157596, "name" : "Testbruker 1", "username" : "testuzer" } }, "_type" : "user" }, { "_id" : "userid123", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { }, "recs" : { }, "user_info" : { "email" : "", "name" : "Firstname Lastname", "phoneNumber" : "", "profilePicture" : "", "pushId" : { }, "username" : "profileName" } }, "_type" : "user" }, { "_id" : "userid42", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { }, "recs" : { }, "user_info" : { "createdAt" : 1475157596, "email" : "e@male.org", "name" : "Firstname Lastname Johnson", "profilePicture" : "", "pushId" : { }, "username" : "userLooser" } }, "_type" : "user" } ], "max_score" : 1, "total" : 3 }, "query" : { ".priority" : 1.477326417484E12, "hits" : [ { "_id" : "test1", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { "test1" : 1 }, "recs" : { }, "user_info" : { "createdAt" : 1475157596, "name" : "Testbruker 1", "username" : "testuzer" } }, "_type" : "user" }, { "_id" : "userid42", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { }, "recs" : { }, "user_info" : { "email" : "", "name" : "Firstname Lastname", "phoneNumber" : "", "profilePicture" : "", "pushId" : { }, "username" : "profileName" } }, "_type" : "user" }, { "_id" : "userid123", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { }, "recs" : { }, "user_info" : { "createdAt" : 1475157596, "email" : "e@male.org", "name" : "Firstname Lastname Johnson", "profilePicture" : "", "pushId" : { }, "username" : "userLooser" } }, "_type" : "user" } ], "max_score" : 1, "total" : 3 }, "type" : { ".priority" : 1.477326417503E12, "hits" : [ { "_id" : "test1", "_index" : "firebase", "_score" : 1, "_source" : { "friends" : { "test1" : 1 }, "recs" : { }, "user_info" : { "createdAt" : 1475157596, "name" : "Testbruker 1", "username" : "testuzer" } }, "_type" : "user" }, { "_id" : "userid42", // Same content as above }, { "_id" : "userid123", // Same content as above } ], "max_score" : 1, "total" : 3 } } } 

哪一个:

  • A)不返回正确的sorting。 第一个结果与我的search查询根本不匹配,看起来像是以随机顺序返回所有用户。
  • B)反应非常混乱。 下/response有三个节点querytypeindex都包含很多的命中。

那么,谁知道什么是错的? 如何创build查询或制作path监视器以便search起作用? 也许得到一个更简单的回应?

Flashlight实际上在search / requests / $ key中查找请求,它应该包含一个带有字段types,索引,查询的文档。 它在search/响应/ $键上的响应与结果。 如果要通过手动添encryption钥来进行testing,请尝试将请求放在另一个节点下,例如search / requests / testkey123。

我试了一下,经过几个小时的努力,我发现:

在我的项目手电筒的.config文件中,我设置了:

 exports.paths = [ { path : "albuns", index: "firebase", type : "album", fields: ['nome'] } ]; 

现在,您需要为Firebase <URL_PROJECT>/search/request/<ID_CREATED_FOR_YOU>.json (使用application / json)发送呼叫http PUT ,您可以使用Postman Extension对其进行testing,

 { "index": "firebase", "type": "album", "q": "John*" }