Skip to content

Latest commit

 

History

History
323 lines (235 loc) · 7.56 KB

quick_start_guide.md

File metadata and controls

323 lines (235 loc) · 7.56 KB

Getting Started

This quick tour will help you get started with MeiliSearch in only a few steps.

Download and launch

First of all, you must have access to a running instance of MeiliSearch.

There are several download possibilities.

:::: tabs ::: tab cURL Download the latest stable release of MeiliSearch with curl.

Launch MeiliSearch to start the server.

$ curl -L https://install.meilisearch.com | sh
$ ./meilisearch
Server is listening on: http://127.0.0.1:7700

:::

::: tab Brew Download the latest stable release of MeiliSearch with Homebrew.

Launch MeiliSearch to start the server.

$ brew update && brew install meilisearch
$ meilisearch
Server is listening on: http://127.0.0.1:7700

:::

::: tab Docker Using Docker you can choose to run any available tags.

This command starts the latest stable release of MeiliSearch.

$ docker run -it --rm -p 7700:7700 -v $(pwd)/data.ms:/data.ms getmeili/meilisearch
Server is listening on: http://0.0.0.0:7700

::: warning Docker is not persistent. You should share a volume to make your container filesystem persistent. MeiliSearch write its data at /data.ms :::

::: tab APT

Download the latest stable release of MeiliSearch with APT.

Launch MeiliSearch to start the server.

$ echo "deb [trusted=yes] https://apt.fury.io/meilisearch/ /" > /etc/apt/sources.list.d/fury.list
$ apt update && apt install meilisearch-http
$ meilisearch
Server is listening on: http://127.0.0.1:7700

:::

::: tab Heroku

You can deploy the latest stable build of MeiliSearch straight on Heroku.

Deploy

The deploy can take up to 20 minutes because it will compile the whole project from the GitHub repository.

::: warning The Heroku filesystem is ephemeral, which means you may lose your data on any restart of the Heroku instance. The Heroku deploy is okay for testing purposes, but it won't work for production. :::

::: tab Source

MeiliSearch is made in Rust. Therefore the Rust toolchain must be installed to compile the project.

If you have the Rust toolchain already installed, you need to clone the repository and go to the cloned directory.

$ git clone https://github.com/meilisearch/MeiliSearch
$ cd MeiliSearch

Inside the folder, compile MeiliSearch.

# Production version
$ cargo build --release

# Debug version
$ cargo build

Compiling in release mode takes more time than in debug mode but the binary process time will be significantly faster. You must run a release binary when using MeiliSearch in production.

You can find the compiled binary in target/debug or target/release.

# Excuting the server binary
$ ./target/release/meilisearch

:::

::::

Environment variables and flags can be set before and on launch. With them you can among other things add the master key or set the port.

Communicate with MeiliSearch

Now that our meilisearch server is up and running, we will be able to communicate with it.

This is done through a RESTFul API or one of our SDKs.

Create your Index

In MeiliSearch, the information is subdivided into indexes. Each index contains a data structure and the associated documents. The indexes can be imagined as SQL tables. But you won't need to define the table, MeiliSearch does that for you.

In order to be able to store our documents in an index, we have to create one first.

:::: tabs

::: tab cURL

API references

$ curl \
  -X POST 'http://localhost:7700/indexes' \
  --data '{
  "name": "Movies",
  "uid" : "movies_uid"
}'

:::

::: tab JS

meili.createIndex({
    name: "Movies",
    uid: "movies_uid"
})

:::

::: tab Ruby

client.create_index(name: 'Movies', uid: 'movies_uid')

:::

::: tab PHP

$client->createIndex('Movies', 'movies_uid');

:::

::: tab Python

client.create_index(name="movies", uid="movies_uid")

::: ::::

Add Documents

Once the index has been created it need to be filled with documents. It is these documents that will be used and returned when searches are made on MeiliSearch.

Documents are sent to MeiliSearch in JSON format.

The documents must have at least one field in common. This field contains the identifier of the document.

Let's use an example movies.json dataset to showcase how to add documents.

:::: tabs

::: tab Curl

API references

$ curl \
  -X POST 'http://localhost:7700/indexes/movies_uid/documents' \
  --data @movies.json

:::

::: tab JS

const movies = require('./movies.json')
meili
    .Index("movies_uid")
    .addDocuments(movies)

:::

::: tab Ruby

index.add_documents(movies)

:::

::: tab PHP

$index->addOrReplaceDocuments($movies);

:::

::: tab Python

index = self.client.get_index(uid="movies_uid")
json_file = open('movies.json')
data = json.load(json_file)
response = index.add_documents(data)

::: ::::

Checking updates

In MeiliSearch, most actions are asynchronous. This lets you stack actions. They will be executed in the order in which they were made.

You can track the state of each action.

Searches

Now that our documents have been added to MeiliSearch we are be able to search in it.

MeiliSearch offers many parameters that you can play with to refine your search or change the format of the returned documents. However, by default the search is already relevant.

The search engine is now aware of our documents and can serve those via our HTTP server.

$ curl 'http://127.0.0.1:7700/indexes/12345678/search?q=botman'

:::: tabs

::: tab Curl

API references

$ curl \
  -X POST 'http://127.0.0.1:7700/indexes/12345678/search?q=botman'

:::

::: tab JS

meili
  .Index('movies')
  .search({
    q: 'batman',
  })
  .then((response) => {
    console.log(response)
  })

:::

::: tab Ruby

index.search('botman')

:::

::: tab PHP

$index->search('botman');

:::

::: tab Python

index.search({
  'q': 'How to Train Your Dragon'
})

::: ::::

MeiliSearch response :

{
  "hits": [
    {
      "id": "29751",
      "title": "Batman Unmasked: The Psychology of the Dark Knight",
      "poster": "https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg",
      "overview": "Delve into the world of Batman and the vigilante justice tha",
      "release_date": "2008-07-15"
    },
    {
      "id": "471474",
      "title": "Batman: Gotham by Gaslight",
      "poster": "https://image.tmdb.org/t/p/w1280/7souLi5zqQCnpZVghaXv0Wowi0y.jpg",
      "overview": "ve Victorian Age Gotham City, Batman begins his war on crime",
      "release_date": "2018-01-12"
    }
  ],
  "offset": 0,
  "limit": 2,
  "processingTimeMs": 1,
  "query": "botman"
}