【问题标题】:Not able to do proper path monitoring or querying with Firebase and ElasticSearch (with Flashlight)无法使用 Firebase 和 ElasticSearch(使用 Flashlight)进行正确的路径监控或查询
【发布时间】:2017-03-06 12:55:36
【问题描述】:

我正在尝试将 ElasticSearch 与 Firebase 集成。我正在使用来自 Firebase 的 Flashlight integration 进行设置。我已按照上面链接的 Github 存储库中的描述将代码部署到 Heroku。

从某种意义上说,当我向/search/request/ 插入查询对象时,我得到/search/response 结果。但是结果有点乱,不正确。但我不知道出了什么问题。

这是config.js 中定义的内容,我在其中定义了要监视的路径:

/** 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"
      }
    }
  }
}

我想要实现的是搜索用户名,并返回排名靠前的结果。我真正需要的只是用户名和用户 ID。

但是当我使用上图中的对象进行查询时,我得到了下面的响应:

  "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) 不返回正确的排序。第一个结果与我的搜索查询完全不匹配,看起来它以随机顺序返回所有用户。
  • B) 回复真是乱七八糟。在/response 下有三个节点querytypeindex 都包含很多的命中。

那么,有谁知道怎么回事?如何创建查询或制作路径监视器以使搜索正常工作?也许得到一个更简单的回应?

【问题讨论】:

    标签: json node.js heroku elasticsearch firebase


    【解决方案1】:

    Flashlight 实际上在 search/requests/$key 中查找请求,其中应该包含一个包含字段类型、索引、查询的文档。它会在 search/response/$key 处对结果做出响应。如果您想通过手动添加密钥进行测试,请尝试将请求放在另一个节点下,例如搜索/请求/testkey123。

    【讨论】:

    • 看那个!这么简单的解决方案,我一直在苦苦挣扎。谢谢你。手电筒文档中应该对此有所了解。
    【解决方案2】:

    我什么都试过了,几个小时后我发现:

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

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

    现在,您需要为 Firebase &lt;URL_PROJECT&gt;/search/request/&lt;ID_CREATED_FOR_YOU&gt;.json 发送调用 http PUT(使用 application/json),您可以使用 Postman Extension 对其进行测试,body 保留:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多