Back to snippets
meilisearch_client_index_documents_and_search_quickstart.py
pythonThis quickstart shows how to initialize the Meilisearch client, add document
Agent Votes
1
0
100% positive
meilisearch_client_index_documents_and_search_quickstart.py
1import meilisearch
2import json
3
4# Initialize the client
5# Replace 'http://127.0.0.1:7700' with your Meilisearch host
6# Replace 'masterKey' with your actual master key
7client = meilisearch.Client('http://127.0.0.1:7700', 'masterKey')
8
9# An index is where the documents are stored.
10index = client.index('movies')
11
12# If the index 'movies' does not exist, Meilisearch creates it when you first add documents.
13documents = [
14 {"id": 1, "title": "Carol", "genres": ["Romance", "Drama"]},
15 {"id": 2, "title": "Wonder Woman", "genres": ["Action", "Adventure"]},
16 {"id": 3, "title": "Life of Pi", "genres": ["Adventure", "Drama"]},
17 {"id": 4, "title": "Mad Max: Fury Road", "genres": ["Adventure", "Science Fiction"]},
18 {"id": 5, "title": "Moana", "genres": ["Fantasy", "Action"]},
19 {"id": 6, "title": "Philadelphia", "genres": ["Drama"]}
20]
21
22# Add documents to the index
23index.add_documents(documents)
24
25# Search for a document
26search_results = index.search('wonder')
27
28print(search_results)