Implement Algolia on the backend with Express.js

Hello there! I am just starting to dive into the Algolia world. There are many things that I do not quite understand. I have a task to implement Algolia in a web app. The web app is using Express + GraphQL on the backend and React on the front. Also, as the persistence layer, the web is using Postgresql. I think I have a good grasp of what needs to be done on the front, but not on the back. More specifically, I do not understand how to push data from my backend to Algolia.

Should I first query my data and then feed it to index.addObjects? If so, how then I programmatically and periodically run this “push” script?

Building an app using Algolia requires several steps.
First you need to upload your data using addObjects. Then you need to configure your index with the dashboard. And then you should build your UI. For that purpose, there is a library called react-instantsearch that makes creating search UI easy.

Finally you want to keep your data in sync, and for that you should implement a slightly different version of your initial import that pushes the data as they are updated in your database. Ideally it should only update the differences.

Thank you for your response!

Are there any examples how to make such setup in express.js? It would make the lives of thousands of developers easier.

Hi @said.akh

The problem is how you update your database.Using an ORM or a query builder are different cases. If you have an ORM you can probably plug the upload in an database update hook. If you’re using a query builder, when you update some part that needs to be indexed, you send them also to Algolia.

Have you seen this video tutorial: https://www.algolia.com/doc/tutorials/indexing/importing-data/importing-with-the-api/ I think it should help.

Thank you @bobylito. Yes, I have seen that tut. It is pretty general and showing only PHP implementation.

In my case, I am not using any ORM, but knexjs. Can you put together a tutorial for this guy or for any Js ORM?

I would love to see how it is all fit together. I mean initial upload in batching and periodical syncing of updated data.

I think many Js developers will appreciate this effort.