I have user generated data in firestore. for full text search feature I am trying to use elastic app search. I want to deploy Cloud function so whenever a document is written in firestore, a function need to be triggered then the function will index the document.
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()
);
});
Any help will be appreciated. I am developing Mobile App using the following Flutter Firebase Elastic App Search
Sample document in firestore {"id":"1234566", "name": "My name", "description": "My description", etc...}
I would recommend to use the offical ES SDK. It would make your code much more stable and easier to read.
Here is an instruction how to install it and here a simple example.