You’re building a store, a docs site or an admin panel, and your search box runs a SQL LIKE query. A user types “harry poter”, gets zero results, and leaves. In this post I’ll show you how to use Meilisearch with TypeScript to add fast, typo-tolerant search to your app in a few lines of code.
Meilisearch is a free, open-source search engine with a simple API, so you can go from nothing to real search results without a long setup.

What is Meilisearch?
Meilisearch is an open-source search engine built to be fast, easy to set up and easy to customize. It’s designed for performance, so it returns results quickly on both small and large datasets.
Meilisearch also gives you a simple, intuitive API. That makes it a great pick when you want better search without spending a day on configuration before your first query works.
Key features of Meilisearch
Relevant results, even with typos
Meilisearch uses ranking rules that return accurate, relevant results even for messy queries. Typo tolerance and synonym handling mean users still find what they want when they misspell a word or use a different term for the same thing.
Fast indexing
Meilisearch indexes new or updated documents as soon as you send them, so fresh data shows up in search almost right away. Each update runs as an asynchronous task, which you’ll see in the code below.
Full-text search
Meilisearch supports full-text search, which means it looks for keywords and phrases across the whole content of your documents. That’s perfect for apps that need to search inside long text like articles or product descriptions.
Customizable ranking
You can fine-tune the ranking rules to fit your needs. This lets you push certain attributes or documents higher, so you decide what users see first.
Clients for many languages
Thanks to its simple API and solid documentation, Meilisearch is easy to use from TypeScript, Python, PHP, Java, Ruby, Go, C#, Rust, Swift and Dart. If you want a refresher on typed code before the examples, my guide to mastering TypeScript functions covers the basics.
Set up Meilisearch with TypeScript
Here’s the quick path from zero to search results. I’ll use a small list of books as sample data.
Run a Meilisearch server
The TypeScript client talks to a running Meilisearch instance, so start one first. The quickest way is Docker:
docker run -it --rm -p 7700:7700 -e MEILI_MASTER_KEY='aMasterKey' getmeili/meilisearch:latest
Meilisearch now listens on http://localhost:7700. Keep the master key handy because the client needs it, and pick a long random key for anything beyond local testing.
Install the client
To install the official meilisearch-js client with npm (Node Package Manager), run:
npm install meilisearch
This adds the JavaScript/TypeScript client to your project, ready to import.
Connect the client
To connect, import the package and create a Meilisearch client with your host and key:
import { MeiliSearch } from 'meilisearch';
const client = new MeiliSearch({
host: 'http://localhost:7700', // Replace with your MeiliSearch server URL
});
If you get an auth or connection error later, check that the host URL is right and that the key matches the one you passed to the server.
Index your documents
Say you have a collection of books you want to search. To add them to an index, run:
const books = [
{ id: 1, title: 'The Great Gatsby', author: 'F. Scott Fitzgerald' },
{ id: 2, title: 'To Kill a Mockingbird', author: 'Harper Lee' },
// Add more books here
];
const index = client.index('books'); // Create an index named 'books'
(async () => {
await index.addDocuments(books); // Index the list of books
})();
Meilisearch queues the documents as a task and indexes them. On a small dataset like this, they’re searchable within moments.
Search your index
Searching with Meilisearch is a piece of cake:
(async () => {
const searchResults = await index.search('mockingbird'); // Search for 'mockingbird'
console.log(searchResults.hits); // Array of search results
})();
Try a misspelled title on purpose. Typo tolerance should still bring back the right book.
Customize the ranking
To change the order of your search results, update the ranking settings:
const customRankingRules = [
'asc(title)', // Rank by title in ascending order
'desc(author)', // Rank by author in descending order
];
(async () => {
const searchResults = await index.search('kill', {
customRanking: customRankingRules,
});
console.log(searchResults.hits);
})();
Settings updates also run as tasks, so give Meilisearch a moment before you test the new order.
Is Meilisearch a good fit for TypeScript projects?
Meilisearch brings speed, relevance and customization to your search with very little setup. The easy integration and rich features make it a top choice, in my opinion, for TypeScript developers who want accurate, fast search their users will actually enjoy.
It works for a small side project and has the potential to handle a large-scale system too. If your search box still runs LIKE '%term%', I’d suggest giving it an afternoon.
Once Meilisearch runs in Docker, you’ll want to keep an eye on it. My post on setting up Grafana with Docker Compose for Next.js apps is a good next read.
Hope this saves your users from one more “No results found” page. 🔍
Frequently asked questions
Is Meilisearch free to use?
Yes, Meilisearch is open source and you can self-host it for free, for example with Docker. The company behind it also offers a paid hosted service if you'd rather not manage the server yourself.
Can I call Meilisearch directly from the browser?
You can, but never ship your master key to the frontend. Create a search-only API key and use that in client-side code, and keep the master key on your server.
Should Meilisearch replace my database?
No. Treat Meilisearch as a search index that sits next to your main database. Keep your source of truth in the database and push new or updated records to Meilisearch whenever they change.
How do I check whether my documents finished indexing?
Adding documents or changing settings returns a task, and you can check that task's status through the client or the API. Wait until the task shows as succeeded before you test your search results.
Leave a Reply