Skip to content

Instantly share code, notes, and snippets.

@JesseE
Created January 10, 2019 16:20
Show Gist options
  • Save JesseE/8a3871002d742141d3b49d343dc93143 to your computer and use it in GitHub Desktop.
Save JesseE/8a3871002d742141d3b49d343dc93143 to your computer and use it in GitHub Desktop.
Firestore cloud function to update Algolia index on change
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as algoliasearch from 'algoliasearch';
admin.initializeApp();
const client = algoliasearch(
functions.config().algolia.app_id,
functions.config().algolia.api_key
);
const index = client.initIndex('movie_title');
exports.updateMovies = functions.firestore
.document('movies/{movieId}')
.onUpdate((change, context) => {
const newData = change.after.data();
const object = {
objectID: context.params.movieId,
...newData
}
return index.partialUpdateObject(object);
})
@dmvvilela
Copy link

Thanks!!

@AyoLaja
Copy link

AyoLaja commented May 13, 2019

Hi, how do you add algolia info to the config object?

@JesseE
Copy link
Author

JesseE commented Aug 14, 2019

if you have the algolia APP ID and ADMIN API KEY. I believe I got it working by typing this in the command line:
firebase functions:config:set algolia.app_id="APP_ID" algolia.api_key="API_KEY"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment