Skip to content

Search engine

Introduction

Build an "index" over large amounts of text so you can find the most relevant content by keyword in seconds.

Why use it

LIKE '%phone%' starts with a wildcard, so the database cannot use a normal index and must scan row by row. Fine for a few thousand rows; slow at millions. It also cannot do:

  • Tokenization: split “apple phone case” into “apple / phone / case” and match each part.
  • Relevance ranking: put the best matches first.
  • Fault tolerance: still find results after a typo.
  • Highlighting and faceted counts (filter panels).

When you do not need it

With little data (tens of thousands of rows or fewer) and only exact or prefix matches, the database’s own indexes or full-text search (such as PostgreSQL full-text search) is enough — do not rush to run another system.

How to do it

A search engine is not the system of record; it is a replica:

  1. Business data still lives in the relational database — see Database choice.
  2. When data changes, sync it to the search engine (via a message queue or outbox).
  3. Queries hit the search engine; when you need details, load them from the database by ID.

Choosing a solution

Option Traits Best for
Elasticsearch Richest features; strong aggregations Large data, log search, complex queries
OpenSearch Forked from Elasticsearch; friendlier open-source license Managed cloud offerings; avoiding license concerns
Meilisearch Easy to deploy; typo tolerance and instant search out of the box Small to mid-size site search

Component comparison

Elasticsearch

Self-hosted open sourceOpen sourceOpsHigh

The best-known dedicated search engine: after building data into an "index", it can quickly do full-text search, filtering and statistics.

Best forProjects with large data volumes and complex search needs (multi-condition filtering, statistics).

Avoid whenSmall data volumes, low-spec servers, or only simple keyword search is needed.

Pros

The most complete features: full-text search, aggregations, log analysis

Still scales with large data volumes

Rich plugins and resources, including Chinese tokenization

Cons

Very memory-hungry; small servers can hardly run it smoothly

Keeping database and search index data in sync requires your own sync logic

Cluster and version-upgrade operations are complex

Official docs ↗

OpenSearch

Self-hosted open sourceOpen sourceOpsHigh

An open-source fork of Elasticsearch maintained by Amazon and others, with usage similar to Elasticsearch.

Best forWanting Elasticsearch-class features with a purely open-source license or a cloud-managed version.

Avoid whenSmall data volumes, or nobody on the team can maintain a cluster.

Pros

The open-source license is permissive, so commercial use has no licensing worry

Features are close to Elasticsearch, so moving over is a low barrier

Cloud vendors already offer a managed version you can use

Cons

It is just as hungry for memory and disk, so operations stay heavy

Newer versions of the API are gradually diverging, so clients cannot be mixed

Chinese-language material is a bit thinner than for Elasticsearch

Official docs ↗

Meilisearch

Self-hosted open sourceOpen sourceOpsLow

A lightweight, out-of-the-box search service known for its "results as you type" experience, with very little configuration.

Best forOn-site search for blogs, products and documentation sites with small to mid data volumes.

Avoid whenYou need complex statistical analysis, or the data volume is very large.

Pros

Easy to install, and default settings already give a good search experience

Supports typo-tolerant matching

Much lower resource usage than Elasticsearch

Cons

Aggregations, complex queries and similar capabilities are far behind Elasticsearch

Mostly single-node, with limited horizontal scaling options at very large data volumes

Chinese tokenization quality needs testing and is less mature than dedicated Chinese tokenizers

Official docs ↗

Typesense

Self-hosted open sourceOpen sourceOpsLow

Another lightweight search service that emphasizes speed and typo tolerance, suited to on-site search.

Best forOn-site search with small to mid data volumes that values an instant-search experience.

Avoid whenVery large data with a limited memory budget, or you need log-analysis features.

Pros

Simple to deploy, small, and very fast search responses

Built-in typo-tolerant matching, so misspelled input still finds results

The index lives in memory, giving low query latency

Cons

The index is in memory, so memory needs are high at large data volumes

Advanced analytics are weaker than Elasticsearch

Smaller community and fewer Chinese-language resources

Official docs ↗

Database-native full-text search (e.g. PostgreSQL)

Built into the frameworkOpsLow

Skip installing a new service and use the database's built-in full-text search directly, keeping search and data in the same place.

Best forEarly-stage projects with modest data that want search working first.

Avoid whenSearch experience is a core selling point, or data is large and searches are frequent.

Pros

No new service, and no separate synchronization to maintain

For a small or medium amount of data, search is entirely enough

Transactions and permissions stay managed by the database

Cons

Chinese word segmentation needs extra work, and the default result is only fair

Ranking, typo tolerance, and highlighting are weaker than a dedicated engine

Search uses the database, and at peak it slows down the rest of the business

The samples below use Meilisearch; Elasticsearch follows the same pattern: create an index, write documents, query by keyword.

Checklist

  • Confirm database indexes or built-in full-text search are truly not enough
  • The database is the only source of truth; the search engine is only a replica
  • Sync is in place, plus a script to rebuild the full index
  • For Chinese content, verify tokenization quality (use a Chinese analyzer plugin if needed)
  • The search service is not exposed to the public internet; keys stay out of code — see Secrets management
  • Search endpoints have rate limiting