Documentation Index Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
This guide walks you through setting up Meilisearch with Go.
Prerequisites
1. Install the SDK
go get github.com/meilisearch/meilisearch-go
2. Connect to Meilisearch
package main
import (
" os "
" github.com/meilisearch/meilisearch-go "
)
func main () {
client := meilisearch . New (
os . Getenv ( "MEILISEARCH_URL" ),
meilisearch . WithAPIKey ( os . Getenv ( "MEILISEARCH_KEY" )),
)
}
Set your environment variables: export MEILISEARCH_URL = "https://your-instance.meilisearch.io" # or http://localhost:7700
export MEILISEARCH_KEY = "your_api_key"
Get a free Cloud instance →
3. Add documents
type Movie struct {
ID int `json:"id"`
Title string `json:"title"`
Genres [] string `json:"genres"`
Year int `json:"year"`
}
movies := [] Movie {
{ ID : 1 , Title : "The Matrix" , Genres : [] string { "Action" , "Sci-Fi" }, Year : 1999 },
{ ID : 2 , Title : "Inception" , Genres : [] string { "Action" , "Thriller" }, Year : 2010 },
{ ID : 3 , Title : "Interstellar" , Genres : [] string { "Drama" , "Sci-Fi" }, Year : 2014 },
}
// Add documents to the 'movies' index
task , _ := client . Index ( "movies" ). AddDocuments ( movies )
// Wait for indexing to complete
client . WaitForTask ( task . TaskUID )
4. Search
results , _ := client . Index ( "movies" ). Search ( "matrix" , nil )
fmt . Println ( results . Hits )
// [map[id:1 title:The Matrix genres:[Action Sci-Fi] year:1999]]
5. Search with filters
First, configure filterable attributes:
client . Index ( "movies" ). UpdateFilterableAttributes ( & [] string { "genres" , "year" })
Then search with filters:
results , _ := client . Index ( "movies" ). Search ( "" , & meilisearch . SearchRequest {
Filter : "genres = 'Sci-Fi' AND year > 2000" ,
})
Full example
package main
import (
" fmt "
" os "
" github.com/meilisearch/meilisearch-go "
)
type Movie struct {
ID int `json:"id"`
Title string `json:"title"`
Genres [] string `json:"genres"`
Year int `json:"year"`
}
func main () {
client := meilisearch . New (
os . Getenv ( "MEILISEARCH_URL" ),
meilisearch . WithAPIKey ( os . Getenv ( "MEILISEARCH_KEY" )),
)
// Add documents
movies := [] Movie {
{ ID : 1 , Title : "The Matrix" , Genres : [] string { "Action" , "Sci-Fi" }, Year : 1999 },
{ ID : 2 , Title : "Inception" , Genres : [] string { "Action" , "Thriller" }, Year : 2010 },
{ ID : 3 , Title : "Interstellar" , Genres : [] string { "Drama" , "Sci-Fi" }, Year : 2014 },
}
task , _ := client . Index ( "movies" ). AddDocuments ( movies )
client . WaitForTask ( task . TaskUID )
// Search
results , _ := client . Index ( "movies" ). Search ( "inter" , nil )
fmt . Println ( results . Hits )
}
Next steps
Full-text search Configure ranking and relevancy
Filtering Add filters and facets
AI-powered search Add semantic search
API reference Explore all search parameters
Resources