Skip to content

Install and set up Typesense

Install Typesense on Ubuntu via APT, set the API key, define a schema-first collection, and verify search latency with curl. Single-node and HA notes.

Typesense is a C++ search engine in the same family as Meilisearch and Algolia — typo-tolerant, low-latency, geared for instant search experiences. Unlike Meilisearch, it ships with a built-in HA cluster mode (Raft consensus) in the open-source build. This article installs Typesense on Ubuntu via the vendor APT repo, defines a schema-first collection, and verifies query latency. Audience is operators bringing up Typesense for product search or autocomplete.

How to verify

After install, confirm the daemon is up and the API key is enforced:

systemctl status typesense-server
journalctl -u typesense-server -n 50 --no-pager
curl -s http://127.0.0.1:8108/health
curl -s -H "X-TYPESENSE-API-KEY: $TS_API_KEY" http://127.0.0.1:8108/collections
curl -sI http://127.0.0.1:8108/collections
ss -tlnp | grep 8108

Without the API key header you get 401; with the key you get [] (empty collections list) on a fresh install.

What’s happening

Typesense runs as a single statically-linked binary (typesense-server). It stores indices on disk under /var/lib/typesense. It uses an in-memory index for hot queries with disk-backed persistence — RAM is the operational constraint, not CPU.

Two design decisions shape the operational shape:

  1. Schema-first. Unlike Meilisearch or Elasticsearch dynamic mapping, Typesense requires you to declare fields up front (string, int32, float, bool, geopoint, plus their *[] array variants). You cannot index a document with a field the schema doesn’t know about.
  2. Built-in HA via Raft. Three nodes form a Raft cluster, share writes through a single leader, and serve reads from any replica. There’s no separate coordinator.

The API uses one master key (api-key flag at launch) and supports scoped keys derived from it for client-side use.

The procedure

1. Install from the official APT repo:

curl -fsSL https://dl.typesense.org/releases/$(curl -s https://api.typesense.org/version)/key.gpg | \
  sudo gpg --dearmor -o /usr/share/keyrings/typesense.gpg
echo "deb [signed-by=/usr/share/keyrings/typesense.gpg] https://dl.typesense.org/apt/ stable main" | \
  sudo tee /etc/apt/sources.list.d/typesense.list
sudo apt update
sudo apt install -y typesense-server

The Debian package creates the systemd unit, a typesense user, and seeds /etc/typesense/typesense-server.ini with a random API key.

2. Generate a strong API key and edit the config:

sudo sed -i "s|^api-key.*|api-key = $(openssl rand -hex 32)|" /etc/typesense/typesense-server.ini
sudo grep ^api-key /etc/typesense/typesense-server.ini

Key fields in /etc/typesense/typesense-server.ini:

api-key = <hex-key>
data-dir = /var/lib/typesense
api-address = 127.0.0.1
api-port = 8108
peering-address = 0.0.0.0
peering-port = 8107

For a single-node setup, leave nodes empty. For HA, set nodes = /etc/typesense/nodes.cfg with three lines:

10.0.0.10:8107:8108
10.0.0.11:8107:8108
10.0.0.12:8107:8108

3. Start the service and capture the key for later:

sudo systemctl enable --now typesense-server
TS_API_KEY=$(sudo grep ^api-key /etc/typesense/typesense-server.ini | awk -F= '{gsub(" ",""); print $2}')
export TS_API_KEY

4. Define a schema and create a collection:

curl -s -X POST 'http://127.0.0.1:8108/collections' \
  -H "X-TYPESENSE-API-KEY: $TS_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "products",
    "fields": [
      {"name": "name",     "type": "string"},
      {"name": "brand",    "type": "string",  "facet": true},
      {"name": "price",    "type": "float",   "facet": true},
      {"name": "in_stock", "type": "bool"}
    ],
    "default_sorting_field": "price"
  }'

5. Index documents and query:

curl -s -X POST 'http://127.0.0.1:8108/collections/products/documents/import?action=create' \
  -H "X-TYPESENSE-API-KEY: $TS_API_KEY" \
  -H 'Content-Type: text/plain' \
  --data-binary $'{"id":"1","name":"Linen shirt","brand":"Apex","price":59.0,"in_stock":true}\n{"id":"2","name":"Linen trousers","brand":"Apex","price":89.0,"in_stock":false}'

curl -s "http://127.0.0.1:8108/collections/products/documents/search?q=lien&query_by=name" \
  -H "X-TYPESENSE-API-KEY: $TS_API_KEY" | jq '.hits[].document.name'

lien is typo’d — Typesense still returns the linen items.

6. Issue a scoped search key for the frontend:

curl -s -X POST 'http://127.0.0.1:8108/keys' \
  -H "X-TYPESENSE-API-KEY: $TS_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"description":"public search","actions":["documents:search"],"collections":["products"]}'

The returned key is the value put in the browser; the parent API key never leaves the server.

Operational notes

  • RAM sizing. Typesense holds the entire index in RAM by default. Budget 2-3 GiB per million small documents as a starting point; measure with /stats.json.
  • HA needs an odd node count — three or five. Two-node Raft is worse than single-node because a split kills quorum.
  • Schema changes require collection alias swaps. Adding a field needs a new collection plus an alias — same pattern as Elasticsearch aliases and rollover.
  • Backups are snapshots. Trigger via the /operations/snapshot endpoint, then archive /var/lib/typesense/snapshot/ to object storage.
  • Latency budget. Healthy installs return p99 search under 50 ms. If you see hundreds of ms, check the nlatest log fields and index size vs RAM.

In the engagements we run, Typesense usually lives as the search backend for a SaaS application with strict latency SLOs. The schema-first model means we treat it like a database — schema migrations are reviewed, scoped keys are issued from secret manager, and snapshot cadence is part of the runbook. See /en/services/managed-operations/ for how we operate search engines as part of the application stack.