Configuring Typesense in GCE #12
flauc
started this conversation in
Full Text Search
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Typesense is a great open-source alternative to elasticsearch and algolia.
It provides a docker image that can easily be self hosted on a VM anywhere. You can do so in GCE by following the steps below.
docker pull typesense/typesense
gcloud config set [your-project]
Configure the docker container in the following way:
--enable-cors
--api-key={key}
- key: some random value--data-dir=/data
--ssl-certificate=/cert/fullchain.pem
--ssl-certificate-key=/cert/privkey.pem
TYPESENSE_API_PORT=443
docker ps -a
to verify that the container has been created anddocker logs [container-id]
to confirm it's running properly.Great work at this point you have a running typesense container.
Configure SSL Certificate
It's important to configure an SSL certificate in order to support https communication which is a requirement for any web application.
The easiest way to do so is through letsencrypt and a certbot authenticating through google dns.
sudo chmod u=rwx,g=rwx,o=rwx /home/letsencrypt/ -R
Note: In order for this to work the domain needs to be registered within google Cloud DNS of the same project.
Accessing the system from a client
The API key you created is an admin key with elevated permissions you shouldn't use it from any client application directly. Instead you should create a search only API key for the website or app and scope it to only public collections.
You can read more about API keys here.
https://extensions.dev/extensions/typesense/firestore-typesense-search
Indexing collections with Firestore
The easiest way to add new indexes to typesense if you're using firebase is by using the firebase typesense extension.
https://extensions.dev/extensions/typesense/firestore-typesense-search
The extension tracks changes in a give collection and automatically in real time syncs them with a collection in typesense. You can install the extension multiple times to track multiple collections. However, you need to create the collection before installing the extension. You can do so through the API:
Note: You don't need to include the id as a field.
If you need to back-fill the collection in typesense you can do so by creating a document
typesense_sync/backfill
with the data{triggered: true}
Beta Was this translation helpful? Give feedback.
All reactions