Package meilisearch is the official Meilisearch SDK for the Go programming language.
The meilisearch-go SDK for Go provides APIs and utilities that developers can use to build Go applications that use meilisearch service.
See the meilisearch package documentation for more information. https://www.meilisearch.com/docs/reference
Example: meili := New("http://localhost:7700", WithAPIKey("foobar")) idx := meili.Index("movies") documents := []map[string]interface{}{ {"id": 1, "title": "Carol", "genres": []string{"Romance", "Drama"}}, {"id": 2, "title": "Wonder Woman", "genres": []string{"Action", "Adventure"}}, {"id": 3, "title": "Life of Pi", "genres": []string{"Adventure", "Drama"}}, {"id": 4, "title": "Mad Max: Fury Road", "genres": []string{"Adventure", "Science Fiction"}}, {"id": 5, "title": "Moana", "genres": []string{"Fantasy", "Action"}}, {"id": 6, "title": "Philadelphia", "genres": []string{"Drama"}}, } task, err := idx.AddDocuments(documents) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(task.TaskUID)
var ( ErrInvalidRequestMethod = errors.New("request body is not expected for GET and HEAD requests") ErrRequestBodyWithoutContentType = errors.New("request body without Content-Type is not allowed") ErrNoSearchRequest = errors.New("no search request provided") ErrNoFacetSearchRequest = errors.New("no search facet request provided") ErrConnectingFailed = errors.New("meilisearch is not connected") ErrMeilisearchNotAvailable = errors.New("meilisearch service is not available") )
General errors
func GetQualifiedVersion() (qualifiedVersion string)
func VersionErrorHintMessage(err error, req *internalRequest) error
VersionErrorHintMessage a hint to the error message if it may come from a version incompatibility with meilisearch
type AddWebhookRequest struct { URL string `json:"url"` }
type AttributeFeatures struct { FacetSearch bool `json:"facetSearch"` Filter FilterFeatures `json:"filter"` }
type AttributeRule struct { AttributePatterns []string `json:"attributePatterns"` Features AttributeFeatures `json:"features"` }
type Batch struct { UID int `json:"uid"` Progress *BatchProgress `json:"progress,omitempty"` Details map[string]interface{} `json:"details,omitempty"` Stats *BatchStats `json:"stats,omitempty"` Duration string `json:"duration,omitempty"` StartedAt time.Time `json:"startedAt,omitempty"` FinishedAt time.Time `json:"finishedAt,omitempty"` BatchStrategy string `json:"batchStrategy,omitempty"` }
Batch gives information about the progress of batch of asynchronous operations.
type BatchProgressStep struct { CurrentStep string `json:"currentStep"` Finished int `json:"finished"` Total int `json:"total"` }
type BatchStatsInternalDatabaseSize struct { ExternalDocumentsIDs string `json:"externalDocumentsIds"` WordDocIDs string `json:"wordDocids"` WordPairProximityDocIDs string `json:"wordPairProximityDocids"` WordPositionDocIDs string `json:"wordPositionDocids"` WordFidDocIDs string `json:"wordFidDocids"` FieldIdWordCountDocIDs string `json:"fieldIdWordCountDocids"` Documents string `json:"documents"` }
type BatchStatsWriteChannelCongestion struct { Attempts int `json:"attempts"` BlockingAttempts int `json:"blocking_attempts"` BlockingRatio float64 `json:"blocking_ratio"` }
BatchesQuery represents the query parameters for listing batches.
type BatchesResults struct { Results []*Batch `json:"results"` Total int64 `json:"total"` Limit int64 `json:"limit"` From int64 `json:"from"` Next int64 `json:"next"` }
CancelTasksQuery is a list of filter available to send as query parameters
type Chat struct { Description string `json:"description,omitempty"` DocumentTemplate string `json:"documentTemplate,omitempty"` DocumentTemplateMaxBytes int `json:"documentTemplateMaxBytes,omitempty"` SearchParameters *SearchParameters `json:"searchParameters,omitempty"` }
type ChatCompletionChoice struct { Index int64 `json:"index"` Delta *ChatCompletionChoiceDelta `json:"delta"` FinishReason *string `json:"finish_reason,omitempty"` Logprobs any `json:"logprobs"` }
type ChatCompletionChoiceDelta struct { Content *string `json:"content,omitempty"` Role *ChatRole `json:"role,omitempty"` Refusal *string `json:"refusal,omitempty"` FunctionCall *string `json:"function_call,omitempty"` ToolCalls *string `json:"tool_calls,omitempty"` }
type ChatCompletionMessage struct { Role ChatRole `json:"role"` Content string `json:"content"` }
type ChatCompletionStreamChunk struct { ID string `json:"id"` Object *string `json:"object,omitempty"` Created Timestampz `json:"created,omitempty"` Model string `json:"model,omitempty"` Choices []*ChatCompletionChoice `json:"choices"` ServiceTier *string `json:"service_tier,omitempty"` SystemFingerprint *string `json:"system_fingerprint,omitempty"` Usage any `json:"usage,omitempty"` }
type ChatReader interface { ChatCompletionStream(workspace string, query *ChatCompletionQuery) (*Stream[*ChatCompletionStreamChunk], error) ChatCompletionStreamWithContext(ctx context.Context, workspace string, query *ChatCompletionQuery) (*Stream[*ChatCompletionStreamChunk], error) ListChatWorkspaces(query *ListChatWorkSpaceQuery) (*ListChatWorkspace, error) ListChatWorkspacesWithContext(ctx context.Context, query *ListChatWorkSpaceQuery) (*ListChatWorkspace, error) GetChatWorkspace(uid string) (*ChatWorkspace, error) GetChatWorkspaceWithContext(ctx context.Context, uid string) (*ChatWorkspace, error) GetChatWorkspaceSettings(uid string) (*ChatWorkspaceSettings, error) GetChatWorkspaceSettingsWithContext(ctx context.Context, uid string) (*ChatWorkspaceSettings, error) }
ChatRole The role of a message in a chat conversation.
ChatSource The source corresponds to a service that generates chat completions from your messages.
type ChatWorkspace struct { UID string `json:"uid"` }
type ChatWorkspaceSettingsPrompts struct { System string `json:"system"` SearchDescription string `json:"searchDescription"` SearchQParam string `json:"searchQParam"` SearchFilterParam string `json:"searchFilterParam"` SearchIndexUidParam string `json:"searchIndexUidParam"` }
type CreateIndexRequest struct { UID string `json:"uid,omitempty"` PrimaryKey string `json:"primaryKey,omitempty"` }
CreateIndexRequest is the request body for create index method
type CsvDocumentsQuery struct { PrimaryKey string `json:"primaryKey,omitempty"` CsvDelimiter string `json:"csvDelimiter,omitempty"` }
DeleteTasksQuery is a list of filter available to send as query parameters
type Details struct { ReceivedDocuments int64 `json:"receivedDocuments,omitempty"` IndexedDocuments int64 `json:"indexedDocuments,omitempty"` DeletedDocuments int64 `json:"deletedDocuments,omitempty"` PrimaryKey string `json:"primaryKey,omitempty"` ProvidedIds int64 `json:"providedIds,omitempty"` RankingRules []string `json:"rankingRules,omitempty"` DistinctAttribute *string `json:"distinctAttribute,omitempty"` SearchableAttributes []string `json:"searchableAttributes,omitempty"` DisplayedAttributes []string `json:"displayedAttributes,omitempty"` StopWords []string `json:"stopWords,omitempty"` Synonyms map[string][]string `json:"synonyms,omitempty"` FilterableAttributes []interface{} `json:"filterableAttributes,omitempty"` SortableAttributes []string `json:"sortableAttributes,omitempty"` TypoTolerance *TypoTolerance `json:"typoTolerance,omitempty"` Faceting *Faceting `json:"faceting,omitempty"` MatchedTasks int64 `json:"matchedTasks,omitempty"` CanceledTasks int64 `json:"canceledTasks,omitempty"` DeletedTasks int64 `json:"deletedTasks,omitempty"` OriginalFilter string `json:"originalFilter,omitempty"` Swaps []SwapIndexesParams `json:"swaps,omitempty"` DumpUid string `json:"dumpUid,omitempty"` }
type Distribution struct { Mean float64 `json:"mean"` Sigma float64 `json:"sigma"` }
Distribution represents a statistical distribution with mean and standard deviation (sigma).
type DocumentManager interface { DocumentReader AddDocuments(documentsPtr interface{}, primaryKey *string) (*TaskInfo, error) AddDocumentsWithContext(ctx context.Context, documentsPtr interface{}, primaryKey *string) (*TaskInfo, error) AddDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey *string) ([]TaskInfo, error) AddDocumentsInBatchesWithContext(ctx context.Context, documentsPtr interface{}, batchSize int, primaryKey *string) ([]TaskInfo, error) AddDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (*TaskInfo, error) AddDocumentsCsvWithContext(ctx context.Context, documents []byte, options *CsvDocumentsQuery) (*TaskInfo, error) AddDocumentsCsvInBatches(documents []byte, batchSize int, options *CsvDocumentsQuery) ([]TaskInfo, error) AddDocumentsCsvInBatchesWithContext(ctx context.Context, documents []byte, batchSize int, options *CsvDocumentsQuery) ([]TaskInfo, error) AddDocumentsCsvFromReaderInBatches(documents io.Reader, batchSize int, options *CsvDocumentsQuery) ([]TaskInfo, error) AddDocumentsCsvFromReaderInBatchesWithContext(ctx context.Context, documents io.Reader, batchSize int, options *CsvDocumentsQuery) ([]TaskInfo, error) AddDocumentsCsvFromReader(documents io.Reader, options *CsvDocumentsQuery) (*TaskInfo, error) AddDocumentsCsvFromReaderWithContext(ctx context.Context, documents io.Reader, options *CsvDocumentsQuery) (*TaskInfo, error) AddDocumentsNdjson(documents []byte, primaryKey *string) (*TaskInfo, error) AddDocumentsNdjsonWithContext(ctx context.Context, documents []byte, primaryKey *string) (*TaskInfo, error) AddDocumentsNdjsonInBatches(documents []byte, batchSize int, primaryKey *string) ([]TaskInfo, error) AddDocumentsNdjsonInBatchesWithContext(ctx context.Context, documents []byte, batchSize int, primaryKey *string) ([]TaskInfo, error) AddDocumentsNdjsonFromReader(documents io.Reader, primaryKey *string) (*TaskInfo, error) AddDocumentsNdjsonFromReaderWithContext(ctx context.Context, documents io.Reader, primaryKey *string) (*TaskInfo, error) AddDocumentsNdjsonFromReaderInBatches(documents io.Reader, batchSize int, primaryKey *string) ([]TaskInfo, error) AddDocumentsNdjsonFromReaderInBatchesWithContext(ctx context.Context, documents io.Reader, batchSize int, primaryKey *string) ([]TaskInfo, error) UpdateDocuments(documentsPtr interface{}, primaryKey *string) (*TaskInfo, error) UpdateDocumentsWithContext(ctx context.Context, documentsPtr interface{}, primaryKey *string) (*TaskInfo, error) UpdateDocumentsInBatches(documentsPtr interface{}, batchSize int, primaryKey *string) ([]TaskInfo, error) UpdateDocumentsInBatchesWithContext(ctx context.Context, documentsPtr interface{}, batchSize int, primaryKey *string) ([]TaskInfo, error) UpdateDocumentsCsv(documents []byte, options *CsvDocumentsQuery) (*TaskInfo, error) UpdateDocumentsCsvWithContext(ctx context.Context, documents []byte, options *CsvDocumentsQuery) (*TaskInfo, error) UpdateDocumentsCsvInBatches(documents []byte, batchsize int, options *CsvDocumentsQuery) ([]TaskInfo, error) UpdateDocumentsCsvInBatchesWithContext(ctx context.Context, documents []byte, batchsize int, options *CsvDocumentsQuery) ([]TaskInfo, error) UpdateDocumentsNdjson(documents []byte, primaryKey *string) (*TaskInfo, error) UpdateDocumentsNdjsonWithContext(ctx context.Context, documents []byte, primaryKey *string) (*TaskInfo, error) UpdateDocumentsNdjsonInBatches(documents []byte, batchsize int, primaryKey *string) ([]TaskInfo, error) UpdateDocumentsNdjsonInBatchesWithContext(ctx context.Context, documents []byte, batchsize int, primaryKey *string) ([]TaskInfo, error) UpdateDocumentsByFunction(req *UpdateDocumentByFunctionRequest) (*TaskInfo, error) UpdateDocumentsByFunctionWithContext(ctx context.Context, req *UpdateDocumentByFunctionRequest) (*TaskInfo, error) DeleteDocument(identifier string) (*TaskInfo, error) DeleteDocumentWithContext(ctx context.Context, identifier string) (*TaskInfo, error) DeleteDocuments(identifiers []string) (*TaskInfo, error) DeleteDocumentsWithContext(ctx context.Context, identifiers []string) (*TaskInfo, error) DeleteDocumentsByFilter(filter interface{}) (*TaskInfo, error) DeleteDocumentsByFilterWithContext(ctx context.Context, filter interface{}) (*TaskInfo, error) DeleteAllDocuments() (*TaskInfo, error) DeleteAllDocumentsWithContext(ctx context.Context) (*TaskInfo, error) }
type DocumentQuery struct { Fields []string `json:"fields,omitempty"` RetrieveVectors bool `json:"retrieveVectors,omitempty"` }
DocumentQuery is the request body get one documents method
type DocumentsQuery struct { Offset int64 `json:"offset,omitempty"` Limit int64 `json:"limit,omitempty"` Fields []string `json:"fields,omitempty"` Filter interface{} `json:"filter,omitempty"` RetrieveVectors bool `json:"retrieveVectors,omitempty"` Ids []string `json:"ids,omitempty"` Sort []string `json:"sort,omitempty"` }
DocumentsQuery is the request body for list documents method
type DocumentsResult struct { Results Hits `json:"results"` Limit int64 `json:"limit"` Offset int64 `json:"offset"` Total int64 `json:"total"` }
type Embedder struct { Source EmbedderSource `json:"source"` URL string `json:"url,omitempty"` APIKey string `json:"apiKey,omitempty"` Model string `json:"model,omitempty"` DocumentTemplate string `json:"documentTemplate,omitempty"` DocumentTemplateMaxBytes int `json:"documentTemplateMaxBytes,omitempty"` Dimensions int `json:"dimensions,omitempty"` Revision string `json:"revision,omitempty"` Distribution *Distribution `json:"distribution,omitempty"` Request map[string]interface{} `json:"request,omitempty"` Response map[string]interface{} `json:"response,omitempty"` BinaryQuantized bool `json:"binaryQuantized,omitempty"` Pooling EmbedderPooling `json:"pooling,omitempty"` IndexingEmbedder *Embedder `json:"indexingEmbedder,omitempty"` SearchEmbedder *Embedder `json:"searchEmbedder,omitempty"` IndexingFragments map[string]Fragment `json:"indexingFragments,omitempty"` SearchFragments map[string]Fragment `json:"searchFragments,omitempty"` }
Embedder represents a unified configuration for various embedder types.
Specs: https://www.meilisearch.com/docs/reference/api/settings#body-21
EmbedderPooling Configure how Meilisearch should merge individual tokens into a single embedding.
pooling is optional for embedders with the huggingFace source.
EmbedderSource The source corresponds to a service that generates embeddings from your documents.
type EncodingCompressionLevel int
ErrCode are all possible errors found during requests
const ( ErrCodeUnknown ErrCode = 0 ErrCodeMarshalRequest ErrCode = iota + 1 ErrCodeResponseUnmarshalBody MeilisearchApiError MeilisearchApiErrorWithoutMessage MeilisearchTimeoutError MeilisearchCommunicationError MeilisearchMaxRetriesExceeded )
Error is the internal error structure that all exposed method use. So ALL errors returned by this library can be cast to this struct (as a pointer)
Error return a well human formatted message.
func (*Error) ErrorBody ΒΆErrorBody add a body to an error
WithErrCode add an error code to an error
type ExperimentalFeaturesBase struct { LogsRoute *bool `json:"logsRoute,omitempty"` Metrics *bool `json:"metrics,omitempty"` EditDocumentsByFunction *bool `json:"editDocumentsByFunction,omitempty"` ContainsFilter *bool `json:"containsFilter,omitempty"` Network *bool `json:"network,omitempty"` CompositeEmbedders *bool `json:"compositeEmbedders,omitempty"` ChatCompletions *bool `json:"chatCompletions,omitempty"` MultiModal *bool `json:"multimodal,omitempty"` }
ExperimentalFeaturesResult represents the experimental features result from the API.
type ExperimentalFeaturesResult struct { LogsRoute bool `json:"logsRoute"` Metrics bool `json:"metrics"` EditDocumentsByFunction bool `json:"editDocumentsByFunction"` ContainsFilter bool `json:"containsFilter"` Network bool `json:"network"` CompositeEmbedders bool `json:"compositeEmbedders"` ChatCompletions bool `json:"chatCompletions"` MultiModal bool `json:"multimodal,omitempty"` }
type ExportParams struct { URL string `json:"url,omitempty"` APIKey string `json:"apiKey,omitempty"` PayloadSize string `json:"payloadSize,omitempty"` Indexes map[string]IndexExportOptions `json:"indexes,omitempty"` }
type FacetSearchRequest struct { FacetName string `json:"facetName,omitempty"` FacetQuery string `json:"facetQuery,omitempty"` Q string `json:"q,omitempty"` Filter string `json:"filter,omitempty"` MatchingStrategy string `json:"matchingStrategy,omitempty"` AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"` ExhaustiveFacetCount bool `json:"exhaustiveFacetCount,omitempty"` }
type FacetSearchResponse struct { FacetHits Hits `json:"facetHits"` FacetQuery string `json:"facetQuery"` ProcessingTimeMs int64 `json:"processingTimeMs"` }
type Faceting struct { MaxValuesPerFacet int64 `json:"maxValuesPerFacet"` SortFacetValuesBy map[string]SortFacetType `json:"sortFacetValuesBy"` }
Faceting is the type that represents the faceting setting in meilisearch
type FilterFeatures struct { Equality bool `json:"equality"` Comparison bool `json:"comparison"` }
type Fragment struct { Value map[string]any `json:"value,omitempty"` }
type Health struct { Status string `json:"status"` }
Health is the request body for set meilisearch health
func (h Hit) Decode(vPtr interface{}) error
Decode decodes a single Hit into the provided struct.
DecodeWith decodes a Hit into the provided struct using the provided marshal and unmarshal functions.
func (h Hits) Decode(vSlicePtr interface{}) error
Decode decodes the Hits into the provided target slice.
DecodeWith decodes a Hits into the provided struct using the provided marshal and unmarshal functions.
type IndexExportOptions struct { Filter string `json:"filter,omitempty"` OverrideSettings bool `json:"overrideSettings,omitempty"` }
type IndexesQuery struct { Limit int64 Offset int64 }
type IndexesResults struct { Results []*IndexResult `json:"results"` Offset int64 `json:"offset"` Limit int64 `json:"limit"` Total int64 `json:"total"` }
IndexesResults return of multiple indexes is wrap in a IndexesResults
type JSONMarshal func(v interface{}) ([]byte, error)
JSONMarshal returns the JSON encoding of v.
type JSONUnmarshal func(data []byte, v interface{}) error
JSONUnmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.
type KeyManager interface { KeyReader CreateKey(request *Key) (*Key, error) CreateKeyWithContext(ctx context.Context, request *Key) (*Key, error) UpdateKey(keyOrUID string, request *Key) (*Key, error) UpdateKeyWithContext(ctx context.Context, keyOrUID string, request *Key) (*Key, error) DeleteKey(keyOrUID string) (bool, error) DeleteKeyWithContext(ctx context.Context, keyOrUID string) (bool, error) }
type KeyParsed struct { Name string `json:"name"` Description string `json:"description"` UID string `json:"uid,omitempty"` Actions []string `json:"actions,omitempty"` Indexes []string `json:"indexes,omitempty"` ExpiresAt *string `json:"expiresAt"` }
KeyParsed this structure is used to send the exact ISO-8601 time format managed by meilisearch
type KeyUpdate struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` }
KeyUpdate this structure is used to update a Key
type KeysQuery struct { Limit int64 Offset int64 }
type KeysResults struct { Results []Key `json:"results"` Offset int64 `json:"offset"` Limit int64 `json:"limit"` Total int64 `json:"total"` }
KeysResults return of multiple keys is wrap in a KeysResults
type ListChatWorkSpaceQuery struct { Limit int64 Offset int64 }
type ListChatWorkspace struct { Results []*ChatWorkspace `json:"results"` Offset int64 `json:"offset"` Limit int64 `json:"limit"` Total int64 `json:"total"` }
type LocalizedAttributes struct { Locales []string `json:"locales,omitempty"` AttributePatterns []string `json:"attributePatterns,omitempty"` }
type MinWordSizeForTypos struct { OneTypo int64 `json:"oneTypo,omitempty"` TwoTypos int64 `json:"twoTypos,omitempty"` }
MinWordSizeForTypos is the type that represents the minWordSizeForTypos setting in the typo tolerance setting in meilisearch
type MultiSearchFederationMergeFacets struct { MaxValuesPerFacet int `json:"maxValuesPerFacet,omitempty"` }
type MultiSearchResponse struct { Results []SearchResponse `json:"results,omitempty"` Hits Hits `json:"hits,omitempty"` ProcessingTimeMs int64 `json:"processingTimeMs,omitempty"` Offset int64 `json:"offset,omitempty"` Limit int64 `json:"limit,omitempty"` EstimatedTotalHits int64 `json:"estimatedTotalHits,omitempty"` SemanticHitCount int64 `json:"semanticHitCount,omitempty"` FacetDistribution map[string]json.RawMessage `json:"facetDistribution,omitempty"` FacetStats map[string]json.RawMessage `json:"facetStats,omitempty"` }
type Option func(*meiliOpt)
DisableRetries disable retry logic in client
WithContentEncoding support the Content-Encoding header indicates the media type is compressed by a given algorithm. compression improves transfer speed and reduces bandwidth consumption by sending and receiving smaller payloads. the Accept-Encoding header, instead, indicates the compression algorithm the client understands.
more: https://www.meilisearch.com/docs/reference/api/overview#content-encoding
WithCustomClient set custom http.Client
WithCustomClientWithTLS client support tls configuration
WithCustomDialContext sets a custom dial context
WithCustomExpectContinueTimeout sets the Expect-Continue timeout
WithCustomIdleConnTimeout sets the idle connection timeout
WithCustomJsonMarshaler set custom marshal from external packages instead encoding/json. we use encoding/json as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of encoding/json.
supported package: goccy/go-json, bytedance/sonic, segmentio/encoding, minio/simdjson-go, wI2L/jettison, mailru/easyjson.
default is encoding/json
WithCustomJsonUnmarshaler set custom unmarshal from external packages instead encoding/json. we use encoding/json as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of encoding/json.
supported package: goccy/go-json, bytedance/sonic, segmentio/encoding, minio/simdjson-go, wI2L/jettison, mailru/easyjson.
default is encoding/json
func WithCustomMaxIdleConns(maxIdleConns int) Option
WithCustomMaxIdleConns sets the max number of idle connections
func WithCustomMaxIdleConnsPerHost(maxIdleConnsPerHost int) Option
WithCustomMaxIdleConnsPerHost sets max idle connections per host
WithCustomProxy sets a custom proxy function
WithCustomRetries set retry on specific http error code and max retries (min: 1, max: 255)
type Pagination struct { }
Pagination is the type that represents the pagination setting in meilisearch
type ProximityPrecisionType string
type SearchFederationOptions struct { Weight float64 `json:"weight,omitempty"` Remote string `json:"remote,omitempty"` }
type SearchParameters struct { Limit int64 `json:"limit,omitempty"` AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"` MatchingStrategy MatchingStrategy `json:"matchingStrategy,omitempty"` Sort []string `json:"sort,omitempty"` Distinct string `json:"distinct,omitempty"` Hybrid *SearchRequestHybrid `json:"hybrid,omitempty"` RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"` }
type SearchReader interface { Search(query string, request *SearchRequest) (*SearchResponse, error) SearchWithContext(ctx context.Context, query string, request *SearchRequest) (*SearchResponse, error) SearchRaw(query string, request *SearchRequest) (*json.RawMessage, error) SearchRawWithContext(ctx context.Context, query string, request *SearchRequest) (*json.RawMessage, error) FacetSearch(request *FacetSearchRequest) (*json.RawMessage, error) FacetSearchWithContext(ctx context.Context, request *FacetSearchRequest) (*json.RawMessage, error) SearchSimilarDocuments(param *SimilarDocumentQuery, resp *SimilarDocumentResult) error SearchSimilarDocumentsWithContext(ctx context.Context, param *SimilarDocumentQuery, resp *SimilarDocumentResult) error }
type SearchRequest struct { Offset int64 `json:"offset,omitempty"` Limit int64 `json:"limit,omitempty"` AttributesToRetrieve []string `json:"attributesToRetrieve,omitempty"` AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"` AttributesToCrop []string `json:"attributesToCrop,omitempty"` CropLength int64 `json:"cropLength,omitempty"` CropMarker string `json:"cropMarker,omitempty"` AttributesToHighlight []string `json:"attributesToHighlight,omitempty"` HighlightPreTag string `json:"highlightPreTag,omitempty"` HighlightPostTag string `json:"highlightPostTag,omitempty"` MatchingStrategy MatchingStrategy `json:"matchingStrategy,omitempty"` Filter interface{} `json:"filter,omitempty"` ShowMatchesPosition bool `json:"showMatchesPosition,omitempty"` ShowRankingScore bool `json:"showRankingScore,omitempty"` ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"` Facets []string `json:"facets,omitempty"` Sort []string `json:"sort,omitempty"` Vector []float32 `json:"vector,omitempty"` HitsPerPage int64 `json:"hitsPerPage,omitempty"` Page int64 `json:"page,omitempty"` IndexUID string `json:"indexUid,omitempty"` Query string `json:"q"` Distinct string `json:"distinct,omitempty"` Hybrid *SearchRequestHybrid `json:"hybrid"` RetrieveVectors bool `json:"retrieveVectors,omitempty"` RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"` FederationOptions *SearchFederationOptions `json:"federationOptions,omitempty"` Locales []string `json:"locales,omitempty"` Media map[string]any `json:"media,omitempty"` }
SearchRequest is the request url param needed for a search query. This struct will be converted to url param before sent.
Documentation: https://www.meilisearch.com/docs/reference/api/search#search-parameters
type SearchRequestHybrid struct { SemanticRatio float64 `json:"semanticRatio,omitempty"` Embedder string `json:"embedder"` }
type SearchResponse struct { Hits Hits `json:"hits"` EstimatedTotalHits int64 `json:"estimatedTotalHits,omitempty"` Offset int64 `json:"offset,omitempty"` Limit int64 `json:"limit,omitempty"` ProcessingTimeMs int64 `json:"processingTimeMs"` Query string `json:"query"` FacetDistribution json.RawMessage `json:"facetDistribution,omitempty"` TotalHits int64 `json:"totalHits,omitempty"` HitsPerPage int64 `json:"hitsPerPage,omitempty"` Page int64 `json:"page,omitempty"` TotalPages int64 `json:"totalPages,omitempty"` FacetStats json.RawMessage `json:"facetStats,omitempty"` IndexUID string `json:"indexUid,omitempty"` }
SearchResponse is the response body for search method
type ServiceManager interface { ServiceReader KeyManager TaskManager ChatManager ChatReader WebhookManager ServiceReader() ServiceReader TaskManager() TaskManager TaskReader() TaskReader KeyManager() KeyManager KeyReader() KeyReader ChatManager() ChatManager ChatReader() ChatReader WebhookManager() WebhookManager WebhookReader() WebhookReader CreateIndex(config *IndexConfig) (*TaskInfo, error) CreateIndexWithContext(ctx context.Context, config *IndexConfig) (*TaskInfo, error) DeleteIndex(uid string) (*TaskInfo, error) DeleteIndexWithContext(ctx context.Context, uid string) (*TaskInfo, error) SwapIndexes(param []*SwapIndexesParams) (*TaskInfo, error) SwapIndexesWithContext(ctx context.Context, param []*SwapIndexesParams) (*TaskInfo, error) GenerateTenantToken(apiKeyUID string, searchRules map[string]interface{}, options *TenantTokenOptions) (string, error) CreateDump() (*TaskInfo, error) CreateDumpWithContext(ctx context.Context) (*TaskInfo, error) CreateSnapshot() (*TaskInfo, error) CreateSnapshotWithContext(ctx context.Context) (*TaskInfo, error) ExperimentalFeatures() *ExperimentalFeatures Export(params *ExportParams) (*TaskInfo, error) ExportWithContext(ctx context.Context, params *ExportParams) (*TaskInfo, error) Close() }
Connect create service manager and check connection with meilisearch
meili, err := Connect("http://localhost:7700", WithAPIKey("foobar")) if err != nil { fmt.Println(err) return } ver, err := meili.Version() if err != nil { fmt.Println(err) return } fmt.Println(ver.PkgVersion)
New create new service manager for operating on meilisearch
// WithAPIKey is optional meili := New("http://localhost:7700", WithAPIKey("foobar")) // An index is where the documents are stored. idx := meili.Index("movies") // If the index 'movies' does not exist, Meilisearch creates it when you first add the documents. documents := []map[string]interface{}{ {"id": 1, "title": "Carol", "genres": []string{"Romance", "Drama"}}, {"id": 2, "title": "Wonder Woman", "genres": []string{"Action", "Adventure"}}, {"id": 3, "title": "Life of Pi", "genres": []string{"Adventure", "Drama"}}, {"id": 4, "title": "Mad Max: Fury Road", "genres": []string{"Adventure", "Science Fiction"}}, {"id": 5, "title": "Moana", "genres": []string{"Fantasy", "Action"}}, {"id": 6, "title": "Philadelphia", "genres": []string{"Drama"}}, } task, err := idx.AddDocuments(documents, nil) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(task.TaskUID)
type ServiceReader interface { Index(uid string) IndexManager GetIndex(indexID string) (*IndexResult, error) GetIndexWithContext(ctx context.Context, indexID string) (*IndexResult, error) GetRawIndex(uid string) (map[string]interface{}, error) GetRawIndexWithContext(ctx context.Context, uid string) (map[string]interface{}, error) ListIndexes(param *IndexesQuery) (*IndexesResults, error) ListIndexesWithContext(ctx context.Context, param *IndexesQuery) (*IndexesResults, error) GetRawIndexes(param *IndexesQuery) (map[string]interface{}, error) GetRawIndexesWithContext(ctx context.Context, param *IndexesQuery) (map[string]interface{}, error) MultiSearch(queries *MultiSearchRequest) (*MultiSearchResponse, error) MultiSearchWithContext(ctx context.Context, queries *MultiSearchRequest) (*MultiSearchResponse, error) GetStats() (*Stats, error) GetStatsWithContext(ctx context.Context) (*Stats, error) Version() (*Version, error) VersionWithContext(ctx context.Context) (*Version, error) Health() (*Health, error) HealthWithContext(ctx context.Context) (*Health, error) IsHealthy() bool GetBatches(param *BatchesQuery) (*BatchesResults, error) GetBatchesWithContext(ctx context.Context, param *BatchesQuery) (*BatchesResults, error) GetBatch(batchUID int) (*Batch, error) GetBatchWithContext(ctx context.Context, batchUID int) (*Batch, error) }
type Settings struct { RankingRules []string `json:"rankingRules,omitempty"` DistinctAttribute *string `json:"distinctAttribute,omitempty"` SearchableAttributes []string `json:"searchableAttributes,omitempty"` Dictionary []string `json:"dictionary,omitempty"` SearchCutoffMs int64 `json:"searchCutoffMs,omitempty"` ProximityPrecision ProximityPrecisionType `json:"proximityPrecision,omitempty"` SeparatorTokens []string `json:"separatorTokens,omitempty"` NonSeparatorTokens []string `json:"nonSeparatorTokens,omitempty"` DisplayedAttributes []string `json:"displayedAttributes,omitempty"` StopWords []string `json:"stopWords,omitempty"` Synonyms map[string][]string `json:"synonyms,omitempty"` FilterableAttributes []string `json:"filterableAttributes,omitempty"` SortableAttributes []string `json:"sortableAttributes,omitempty"` LocalizedAttributes []*LocalizedAttributes `json:"localizedAttributes,omitempty"` TypoTolerance *TypoTolerance `json:"typoTolerance,omitempty"` Faceting *Faceting `json:"faceting,omitempty"` Embedders map[string]Embedder `json:"embedders,omitempty"` PrefixSearch *string `json:"prefixSearch,omitempty"` FacetSearch bool `json:"facetSearch,omitempty"` Chat *Chat `json:"chat,omitempty"` }
Settings is the type that represents the settings in meilisearch
type SettingsManager interface { SettingsReader UpdateSettings(request *Settings) (*TaskInfo, error) UpdateSettingsWithContext(ctx context.Context, request *Settings) (*TaskInfo, error) ResetSettings() (*TaskInfo, error) ResetSettingsWithContext(ctx context.Context) (*TaskInfo, error) UpdateRankingRules(request *[]string) (*TaskInfo, error) UpdateRankingRulesWithContext(ctx context.Context, request *[]string) (*TaskInfo, error) ResetRankingRules() (*TaskInfo, error) ResetRankingRulesWithContext(ctx context.Context) (*TaskInfo, error) UpdateDistinctAttribute(request string) (*TaskInfo, error) UpdateDistinctAttributeWithContext(ctx context.Context, request string) (*TaskInfo, error) ResetDistinctAttribute() (*TaskInfo, error) ResetDistinctAttributeWithContext(ctx context.Context) (*TaskInfo, error) UpdateSearchableAttributes(request *[]string) (*TaskInfo, error) UpdateSearchableAttributesWithContext(ctx context.Context, request *[]string) (*TaskInfo, error) ResetSearchableAttributes() (*TaskInfo, error) ResetSearchableAttributesWithContext(ctx context.Context) (*TaskInfo, error) UpdateDisplayedAttributes(request *[]string) (*TaskInfo, error) UpdateDisplayedAttributesWithContext(ctx context.Context, request *[]string) (*TaskInfo, error) ResetDisplayedAttributes() (*TaskInfo, error) ResetDisplayedAttributesWithContext(ctx context.Context) (*TaskInfo, error) UpdateStopWords(request *[]string) (*TaskInfo, error) UpdateStopWordsWithContext(ctx context.Context, request *[]string) (*TaskInfo, error) ResetStopWords() (*TaskInfo, error) ResetStopWordsWithContext(ctx context.Context) (*TaskInfo, error) UpdateSynonyms(request *map[string][]string) (*TaskInfo, error) UpdateSynonymsWithContext(ctx context.Context, request *map[string][]string) (*TaskInfo, error) ResetSynonyms() (*TaskInfo, error) ResetSynonymsWithContext(ctx context.Context) (*TaskInfo, error) UpdateFilterableAttributes(request *[]interface{}) (*TaskInfo, error) UpdateFilterableAttributesWithContext(ctx context.Context, request *[]interface{}) (*TaskInfo, error) ResetFilterableAttributes() (*TaskInfo, error) ResetFilterableAttributesWithContext(ctx context.Context) (*TaskInfo, error) UpdateSortableAttributes(request *[]string) (*TaskInfo, error) UpdateSortableAttributesWithContext(ctx context.Context, request *[]string) (*TaskInfo, error) ResetSortableAttributes() (*TaskInfo, error) ResetSortableAttributesWithContext(ctx context.Context) (*TaskInfo, error) UpdateTypoTolerance(request *TypoTolerance) (*TaskInfo, error) UpdateTypoToleranceWithContext(ctx context.Context, request *TypoTolerance) (*TaskInfo, error) ResetTypoTolerance() (*TaskInfo, error) ResetTypoToleranceWithContext(ctx context.Context) (*TaskInfo, error) UpdatePagination(request *Pagination) (*TaskInfo, error) UpdatePaginationWithContext(ctx context.Context, request *Pagination) (*TaskInfo, error) ResetPagination() (*TaskInfo, error) ResetPaginationWithContext(ctx context.Context) (*TaskInfo, error) UpdateFaceting(request *Faceting) (*TaskInfo, error) UpdateFacetingWithContext(ctx context.Context, request *Faceting) (*TaskInfo, error) ResetFaceting() (*TaskInfo, error) ResetFacetingWithContext(ctx context.Context) (*TaskInfo, error) UpdateEmbedders(request map[string]Embedder) (*TaskInfo, error) UpdateEmbeddersWithContext(ctx context.Context, request map[string]Embedder) (*TaskInfo, error) ResetEmbedders() (*TaskInfo, error) ResetEmbeddersWithContext(ctx context.Context) (*TaskInfo, error) UpdateSearchCutoffMs(request int64) (*TaskInfo, error) UpdateSearchCutoffMsWithContext(ctx context.Context, request int64) (*TaskInfo, error) ResetSearchCutoffMs() (*TaskInfo, error) ResetSearchCutoffMsWithContext(ctx context.Context) (*TaskInfo, error) UpdateSeparatorTokens(tokens []string) (*TaskInfo, error) UpdateSeparatorTokensWithContext(ctx context.Context, tokens []string) (*TaskInfo, error) ResetSeparatorTokens() (*TaskInfo, error) ResetSeparatorTokensWithContext(ctx context.Context) (*TaskInfo, error) UpdateNonSeparatorTokens(tokens []string) (*TaskInfo, error) UpdateNonSeparatorTokensWithContext(ctx context.Context, tokens []string) (*TaskInfo, error) ResetNonSeparatorTokens() (*TaskInfo, error) ResetNonSeparatorTokensWithContext(ctx context.Context) (*TaskInfo, error) UpdateDictionary(words []string) (*TaskInfo, error) UpdateDictionaryWithContext(ctx context.Context, words []string) (*TaskInfo, error) ResetDictionary() (*TaskInfo, error) ResetDictionaryWithContext(ctx context.Context) (*TaskInfo, error) UpdateProximityPrecision(proximityType ProximityPrecisionType) (*TaskInfo, error) UpdateProximityPrecisionWithContext(ctx context.Context, proximityType ProximityPrecisionType) (*TaskInfo, error) ResetProximityPrecision() (*TaskInfo, error) ResetProximityPrecisionWithContext(ctx context.Context) (*TaskInfo, error) UpdateLocalizedAttributes(request []*LocalizedAttributes) (*TaskInfo, error) UpdateLocalizedAttributesWithContext(ctx context.Context, request []*LocalizedAttributes) (*TaskInfo, error) ResetLocalizedAttributes() (*TaskInfo, error) ResetLocalizedAttributesWithContext(ctx context.Context) (*TaskInfo, error) UpdatePrefixSearch(request string) (*TaskInfo, error) UpdatePrefixSearchWithContext(ctx context.Context, request string) (*TaskInfo, error) ResetPrefixSearch() (*TaskInfo, error) ResetPrefixSearchWithContext(ctx context.Context) (*TaskInfo, error) UpdateFacetSearch(request bool) (*TaskInfo, error) UpdateFacetSearchWithContext(ctx context.Context, request bool) (*TaskInfo, error) ResetFacetSearch() (*TaskInfo, error) ResetFacetSearchWithContext(ctx context.Context) (*TaskInfo, error) }
type SettingsReader interface { GetSettings() (*Settings, error) GetSettingsWithContext(ctx context.Context) (*Settings, error) GetRankingRules() (*[]string, error) GetRankingRulesWithContext(ctx context.Context) (*[]string, error) GetDistinctAttribute() (*string, error) GetDistinctAttributeWithContext(ctx context.Context) (*string, error) GetSearchableAttributes() (*[]string, error) GetSearchableAttributesWithContext(ctx context.Context) (*[]string, error) GetDisplayedAttributes() (*[]string, error) GetDisplayedAttributesWithContext(ctx context.Context) (*[]string, error) GetStopWords() (*[]string, error) GetStopWordsWithContext(ctx context.Context) (*[]string, error) GetSynonyms() (*map[string][]string, error) GetSynonymsWithContext(ctx context.Context) (*map[string][]string, error) GetFilterableAttributes() (*[]interface{}, error) GetFilterableAttributesWithContext(ctx context.Context) (*[]interface{}, error) GetSortableAttributes() (*[]string, error) GetSortableAttributesWithContext(ctx context.Context) (*[]string, error) GetTypoTolerance() (*TypoTolerance, error) GetTypoToleranceWithContext(ctx context.Context) (*TypoTolerance, error) GetPagination() (*Pagination, error) GetPaginationWithContext(ctx context.Context) (*Pagination, error) GetFaceting() (*Faceting, error) GetFacetingWithContext(ctx context.Context) (*Faceting, error) GetEmbedders() (map[string]Embedder, error) GetEmbeddersWithContext(ctx context.Context) (map[string]Embedder, error) GetSearchCutoffMs() (int64, error) GetSearchCutoffMsWithContext(ctx context.Context) (int64, error) GetSeparatorTokens() ([]string, error) GetSeparatorTokensWithContext(ctx context.Context) ([]string, error) GetNonSeparatorTokens() ([]string, error) GetNonSeparatorTokensWithContext(ctx context.Context) ([]string, error) GetDictionary() ([]string, error) GetDictionaryWithContext(ctx context.Context) ([]string, error) GetProximityPrecision() (ProximityPrecisionType, error) GetProximityPrecisionWithContext(ctx context.Context) (ProximityPrecisionType, error) GetLocalizedAttributes() ([]*LocalizedAttributes, error) GetLocalizedAttributesWithContext(ctx context.Context) ([]*LocalizedAttributes, error) GetPrefixSearch() (*string, error) GetPrefixSearchWithContext(ctx context.Context) (*string, error) GetFacetSearch() (bool, error) GetFacetSearchWithContext(ctx context.Context) (bool, error) }
type SimilarDocumentQuery struct { Id interface{} `json:"id,omitempty"` Embedder string `json:"embedder"` AttributesToRetrieve []string `json:"attributesToRetrieve,omitempty"` Offset int64 `json:"offset,omitempty"` Limit int64 `json:"limit,omitempty"` Filter string `json:"filter,omitempty"` ShowRankingScore bool `json:"showRankingScore,omitempty"` ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"` RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"` RetrieveVectors bool `json:"retrieveVectors,omitempty"` }
SimilarDocumentQuery is query parameters of similar documents
type SimilarDocumentResult struct { Hits Hits `json:"hits,omitempty"` ID string `json:"id,omitempty"` ProcessingTimeMS int64 `json:"processingTimeMs,omitempty"` Limit int64 `json:"limit,omitempty"` Offset int64 `json:"offset,omitempty"` EstimatedTotalHits int64 `json:"estimatedTotalHits,omitempty"` }
type Stats struct { DatabaseSize int64 `json:"databaseSize"` UsedDatabaseSize int64 `json:"usedDatabaseSize"` LastUpdate time.Time `json:"lastUpdate"` Indexes map[string]StatsIndex `json:"indexes"` }
Stats is the type that represent all stats
type StatsIndex struct { NumberOfDocuments int64 `json:"numberOfDocuments"` IsIndexing bool `json:"isIndexing"` FieldDistribution map[string]int64 `json:"fieldDistribution"` RawDocumentDbSize int64 `json:"rawDocumentDbSize"` AvgDocumentSize int64 `json:"avgDocumentSize"` NumberOfEmbeddedDocuments int64 `json:"numberOfEmbeddedDocuments"` NumberOfEmbeddings int64 `json:"numberOfEmbeddings"` }
StatsIndex is the type that represent the stats of an index in meilisearch
type Stream[T any] struct { }
func (s *Stream[T]) Current() T
type SwapIndexesParams struct { Indexes []string `json:"indexes"` }
type TaskReader interface { GetTask(taskUID int64) (*Task, error) GetTaskWithContext(ctx context.Context, taskUID int64) (*Task, error) GetTasks(param *TasksQuery) (*TaskResult, error) GetTasksWithContext(ctx context.Context, param *TasksQuery) (*TaskResult, error) WaitForTask(taskUID int64, interval time.Duration) (*Task, error) WaitForTaskWithContext(ctx context.Context, taskUID int64, interval time.Duration) (*Task, error) }
type TaskResult struct { Results []Task `json:"results"` Limit int64 `json:"limit"` From int64 `json:"from"` Next int64 `json:"next"` Total int64 `json:"total"` }
TaskResult return of multiple tasks is wrap in a TaskResult
const ( TaskTypeIndexCreation TaskType = "indexCreation" TaskTypeIndexUpdate TaskType = "indexUpdate" TaskTypeIndexDeletion TaskType = "indexDeletion" TaskTypeIndexSwap TaskType = "indexSwap" TaskTypeDocumentAdditionOrUpdate TaskType = "documentAdditionOrUpdate" TaskTypeDocumentDeletion TaskType = "documentDeletion" TaskTypeSettingsUpdate TaskType = "settingsUpdate" TaskTypeDumpCreation TaskType = "dumpCreation" TaskTypeTaskCancelation TaskType = "taskCancelation" TaskTypeTaskDeletion TaskType = "taskDeletion" TaskTypeSnapshotCreation TaskType = "snapshotCreation" TaskTypeExport TaskType = "export" )
TasksQuery is a list of filter available to send as query parameters
type TenantTokenClaims struct { APIKeyUID string `json:"apiKeyUid"` SearchRules interface{} `json:"searchRules"` jwt.RegisteredClaims }
TenantTokenClaims custom Claims structure to create a Tenant Token
TenantTokenOptions information to create a tenant token
ExpiresAt is a time.Time when the key will expire. Note that if an ExpiresAt value is included it should be in UTC time. ApiKey is the API key parent of the token.
type TypoTolerance struct { Enabled bool `json:"enabled"` MinWordSizeForTypos MinWordSizeForTypos `json:"minWordSizeForTypos,omitempty"` DisableOnWords []string `json:"disableOnWords,omitempty"` DisableOnAttributes []string `json:"disableOnAttributes,omitempty"` DisableOnNumbers bool `json:"disableOnNumbers,omitempty"` }
TypoTolerance is the type that represents the typo tolerance setting in meilisearch
type UpdateDocumentByFunctionRequest struct { Filter string `json:"filter,omitempty"` Function string `json:"function"` Context map[string]interface{} `json:"context,omitempty"` }
type UpdateIndexRequest struct { PrimaryKey string `json:"primaryKey"` }
UpdateIndexRequest is the request body for update Index primary key
type UpdateWebhookRequest struct { URL string `json:"url,omitempty"` }
type Version struct { CommitSha string `json:"commitSha"` CommitDate string `json:"commitDate"` PkgVersion string `json:"pkgVersion"` }
Version is the type that represents the versions in meilisearch
type Webhook struct { UUID string `json:"uuid"` IsEditable bool `json:"isEditable"` URL string `json:"url"` }
type WebhookResults struct { Result []*Webhook `json:"results"` }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4