0

我在 Firestore 中有用户生成的数据。对于全文搜索功能,我正在尝试使用弹性应用搜索。我想部署 Cloud 功能,因此每当在 Firestore 中写入文档时,都需要触发一个函数,然后该函数将索引该文档。

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const axios = require("axios");
admin.initializeApp(functions.config().firebase);
exports.createBPS = functions.firestore
    .document("MyCollection/{docId}")
    .onWrite((snap, context) => {
      axios.post(
          "https://myapp.ent.us-west1.gcp.cloud.es.io/api/as/v1/engines/myengine/documents?auth_token=private-aadsafdsfadsfdsafdafd",
          snap.after.data()
      );
});

任何帮助将不胜感激。我正在使用以下 Flutter Firebase Elastic App Search 开发移动应用程序

firestore 中的示例文档 {"id":"1234566", "name": "My name", "description": "My description" 等...}

4

2 回答 2

0

我建议使用官方的 ES SDK。这将使您的代码更加稳定和易于阅读。

是如何安装它的说明,这里是一个简单的示例。

于 2021-07-21T12:11:40.723 回答
0

您可以在 Firebase 的扩展页面上查看以下指南。


(可选)回填或导入现有文档 此扩展仅发送已更改文档的内容 - 它不会将现有文档的完整数据集导出到 App Search。因此,要使用集合中的所有文档回填数据集,您可以运行此扩展提供的导入脚本。

在运行脚本之前,首先按照此处的说明“为您的服务帐户生成私钥文件”。下载它并将其保存为 serviceAccountKey.json。

GOOGLE_APPLICATION_CREDENTIALS= /path/to/your/serviceAccountKey.json \
COLLECTION_PATH=TodoItem \
INDEXED_FIELDS=content,isPublic, writerID \
ENTERPRISE_SEARCH_URL=https://todomateelastic.ent.us-central1.gcp.cloud.es.io \
APP_SEARCH_API_KEY= { your private app search API key here } \
APP_SEARCH_ENGINE_NAME=todomatecontent \
npx @elastic/app-search-firestore-extension import
于 2022-03-05T17:05:21.030 回答