Need help with meilisearch-js?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

173 Stars 18 Forks MIT License 962 Commits 25 Opened issues


Javascript client for the MeiliSearch API

Services available


Need anything else?

Contributors list


MeiliSearch JavaScript

MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ

npm version Tests Prettier License Bors enabled

⚡ The MeiliSearch API client written for JavaScript

MeiliSearch JavaScript is the MeiliSearch API client for JavaScript developers.

MeiliSearch is an open-source search engine. Discover what MeiliSearch is!

Table of Contents <!-- omit in toc -->

📖 Documentation

See our Documentation or our API References.

🔧 Installation


npm install meilisearch


yarn add meilisearch

🏃‍♀️ Run MeiliSearch <!-- omit in toc -->

There are many easy ways to download and run a MeiliSearch instance.

For example, if you use Docker:

$ docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
$ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

Import <!-- omit in toc -->

Depending on the environment on which you are using MeiliSearch, imports may differ.

Import Syntax <!-- omit in toc -->

Usage in a ES module environment:

import { MeiliSearch } from 'meilisearch'

const client = new MeiliSearch({ host: '', apiKey: 'masterKey', })

Include Script Tag <!-- omit in toc -->

Usage in an HTML (or alike) file:

Require Syntax <!-- omit in toc -->

Usage in a back-end node environment

const { MeiliSearch } = require('meilisearch')

const client = new MeiliSearch({ host: '', apiKey: 'masterKey', })

React Native <!-- omit in toc -->

To make this package work with React Native, please add the react-native-url-polyfill.

🎬 Getting Started

Add Documents <!-- omit in toc -->

const { MeiliSearch } = require('meilisearch')
// Or if you are in a ES environment
import { MeiliSearch } from 'meilisearch'

;(async () => { const client = new MeiliSearch({ host: '', apiKey: 'masterKey', })

// An index is where the documents are stored. const index = client.index('books') // If your index exists

const documents = [ { book_id: 123, title: 'Pride and Prejudice' }, { book_id: 456, title: 'Le Petit Prince' }, { book_id: 1, title: 'Alice In Wonderland' }, { book_id: 1344, title: 'The Hobbit' }, { book_id: 4, title: 'Harry Potter and the Half-Blood Prince', genre: 'fantasy' }, { book_id: 42, title: "The Hitchhiker's Guide to the Galaxy", genre: 'fantasy' } ]

// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents. let response = await index.addDocuments(documents)

console.log(response) // => { "updateId": 0 } })()

With the

, you can check the status (
) of your documents addition using the update endpoint.

Basic Search <!-- omit in toc -->

// MeiliSearch is typo-tolerant:
const search = await'harry pottre')


  "hits": [
      "book_id": 4,
      "title": "Harry Potter and the Half-Blood Prince"
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "exhaustiveNbHits": false,
  "processingTimeMs": 1,
  "query": "harry pottre"

Custom Search <!-- omit in toc -->

All the supported options are described in the search parameters section of the documentation.

    attributesToHighlight: ['*'],
    filters: 'book_id > 10'
  "hits": [
      "book_id": 456,
      "title": "Le Petit Prince",
      "_formatted": {
        "book_id": 456,
        "title": "Le Petit Prince"
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "exhaustiveNbHits": false,
  "processingTimeMs": 0,
  "query": "prince"

Placeholder Search <!-- omit in toc -->

Placeholder search makes it possible to receive hits based on your parameters without having any query (

    facetFilters: ['genre:fantasy'],
    facetsDistribution: ['genre']
  "hits": [
      "id": 4,
      "title": "Harry Potter and the Half-Blood Prince",
      "genre": "fantasy"
      "id": 42,
      "title": "The Hitchhiker's Guide to the Galaxy",
      "genre": "fantasy"
  "offset": 0,
  "limit": 20,
  "nbHits": 2,
  "exhaustiveNbHits": false,
  "processingTimeMs": 0,
  "query": "",
  "facetsDistribution": { "genre": { "fantasy": 2 } },
  "exhaustiveFacetsCount": true

Abortable Search <!-- omit in toc -->

You can abort a pending search request by providing an AbortSignal to the request.

const controller = new AbortController()

index .search('prince', {}, 'POST', { signal: controller.signal, }) .then((response) => { /** ... */ }) .catch((e) => { /** Catch AbortError here. */ })


🤖 Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.19.0 of MeiliSearch.

💡 Learn More

The following sections may interest you:

This repository also contains more examples.

⚙️ Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!

📜 API Resources

Search <!-- omit in toc -->

  • Make a search request:

client.index('xxx').search(query: string, options: SearchParams = {}, method: 'POST' | 'GET' = 'POST', config?: Partial): Promise>

Indexes <!-- omit in toc -->

  • List all indexes:

client.listIndexes(): Promise
  • Create new index:

client.createIndex(uid: string, options?: IndexOptions): Promise>
  • Create a local reference to an index:

client.index(uid: string): Index
  • Get an index:

client.getIndex(uid: string): Index
  • Get or create index if it does not exist

client.getOrCreateIndex(uid: string, options?: IndexOptions): Promise>
  • Get Index information:

index.getRawInfo(): Promise
  • Update Index:

client.updateIndex(uid): Promise
Or using the index object:
index.update(data: IndexOptions): Promise
  • Delete Index:

client.deleteIndex(uid): Promise
Or using the index object:
index.delete(): Promise
  • Get specific index stats

index.getStats(): Promise
  • Return Index instance with updated information:

index.fetchInfo(): Promise
  • Get Primary Key of an Index:

index.fetchPrimaryKey(): Promise

Updates <!-- omit in toc -->

  • Get One update info:

index.getUpdateStatus(updateId: number): Promise
  • Get all updates info:

index.getAllUpdateStatus(): Promise
  • Wait for pending update:

index.waitForPendingUpdate(updateId: number, { timeOutMs?: number, intervalMs?: number }): Promise

Documents <!-- omit in toc -->

  • Add or replace multiple documents:

index.addDocuments(documents: Document[]): Promise
  • Add or update multiple documents:

index.updateDocuments(documents: Document[]): Promise
  • Get Documents:

index.getDocuments(params: getDocumentsParams): Promise[]>
  • Get one document:

index.getDocument(documentId: string): Promise>
  • Delete one document:

index.deleteDocument(documentId: string | number): Promise
  • Delete multiple documents:

index.deleteDocuments(documentsIds: string[] | number[]): Promise
  • Delete all documents:

index.deleteAllDocuments(): Promise

Settings <!-- omit in toc -->

  • Get settings:

index.getSettings(): Promise
  • Update settings:

index.updateSettings(settings: Settings): Promise
  • Reset settings:

index.resetSettings(): Promise

Synonyms <!-- omit in toc -->

  • Get synonyms:

index.getSynonyms(): Promise
  • Update synonyms:

index.updateSynonyms(synonyms: object): Promise
  • Reset synonyms:

index.resetSynonyms(): Promise

Stop-words <!-- omit in toc -->

  • Get Stop Words

    index.getStopWords(): Promise
  • Update Stop Words

    index.updateStopWords(string[]): Promise
  • Reset Stop Words

    index.resetStopWords(): Promise

Ranking rules <!-- omit in toc -->

  • Get Ranking Rules

    index.getRankingRules(): Promise
  • Update Ranking Rules

    index.updateRankingRules(rankingRules: string[]): Promise
  • Reset Ranking Rules

    index.resetRankingRules(): Promise

Distinct Attribute <!-- omit in toc -->

  • Get Distinct Attribute

    index.getDistinctAttribute(): Promise
  • Update Distinct Attribute

    index.updateDistinctAttribute(distinctAttribute: string): Promise
  • Reset Distinct Attribute

    index.resetDistinctAttribute(): Promise

Searchable Attributes <!-- omit in toc -->

  • Get Searchable Attributes

    index.getSearchableAttributes(): Promise
  • Update Searchable Attributes

    index.updateSearchableAttributes(searchableAttributes: string[]): Promise
  • Reset Searchable Attributes

    index.resetSearchableAttributes(): Promise

Displayed Attributes <!-- omit in toc -->

  • Get Displayed Attributes

    index.getDisplayedAttributes(): Promise
  • Update Displayed Attributes

    index.updateDisplayedAttributes(displayedAttributes: string[]): Promise
  • Reset Displayed Attributes

    index.resetDisplayedAttributes(): Promise

Keys <!-- omit in toc -->

  • Get keys

client.getKeys(): Promise

Healthy <!-- omit in toc -->

  • Check if the server is healthy

client.isHealthy(): Promise

Stats <!-- omit in toc -->

  • Get database stats

client.stats(): Promise

Version <!-- omit in toc -->

  • Get binary version

client.version(): Promise

Dumps <!-- omit in toc -->

  • Trigger a dump creation process

client.createDump(): Promise
  • Get the status of a dump creation process

client.getDumpStatus(dumpUid: string): Promise

MeiliSearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.