Meilisearch is the easy part. The sync worker is where it hurts.
Suppose your product catalog lives in Postgres and search is ILIKE '%term%' . It works, nobody complains, and the table is small. Then hedphones returns nothing, the query plan turns into a sequential scan, and you start reading about Meilisearch. The indexing part is genuinely easy. docker compose up , create the index, push documents, done. The guide linked below walks the whole build and every…
Meilisearch's search functionality works well with a simple ILIKE query, but the worker component that keeps the search index in sync with the database presents challenges. Setting up Meilisearch in Docker compose, indexing 20,002 rows from PostgreSQL, reveals issues with the cursor-based pagination. The timestamp used for updates in PostgreSQL is not accurate, leading to missing documents when incrementing the cursor using "=".
Switching to the equal sign resolves the issue but causes the worker to stall at a specific number of documents. A fix involves using a composite index with both the updated_at timestamp and id field. Another trap lies in the handling of timestamps in PostgreSQL, which converts timestamptz to JavaScript Date objects with milliseconds.
Selecting this column without casting can cause issues with the cursor format. Meilisearch and PostgreSQL return different results for similar queries, with Meilisearch handling prefix matching better. The design choice of strict AND matching and ignoring edit distance comes at the cost of increased storage requirements, with Meilisearch needing roughly 4.3 times more disk space for the same number of documents.
Despite these challenges, the architecture proves beneficial due to the ease of rebuilding the index when issues arise.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.