[英]Exporting data from firebase firestore to MeiliSearch using Google Cloud Function
[英]How to index data from Firebase Firestore to Elastic App Search using Cloud Function?
我在 firestore 中有用戶生成的數據。 對於全文搜索功能,我正在嘗試使用彈性應用程序搜索。 我想部署 Cloud function,所以每當在 firestore 中寫入文檔時,都需要觸發 function,然后 function 將為該文檔編制索引。
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", etc...}
同時有一個 Firebase 擴展可以滿足您的需求: https : //firebase.google.com/products/extensions/elastic-firestore-elastic-app-search
您可以在您的 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.