|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data Meilisearch 0.12.0! |
Meilisearch Repositories
MeilisearchRepository<T, ID> extends Spring Data CrudRepository and PagingAndSortingRepository.
The default implementation delegates to MeilisearchOperations.
This keeps repository usage aligned with familiar Spring Data patterns while still letting the module preserve Meilisearch-specific behavior underneath the repository facade.
import io.vanslog.spring.data.meilisearch.repository.MeilisearchRepository;
public interface MovieRepository extends MeilisearchRepository<Movie, String> {
}
This is the recommended repository style for the current module. It exposes the standard Spring Data CRUD and pagination entry points without implying support for a wider derived-query feature set.
Automatic Settings Application
Repository bootstrap inspects the mapped entity type. If the entity is annotated with @Document(applySettings = true), Spring Data Meilisearch applies its annotation-driven settings through MeilisearchOperations.applySettings(…) when the repository is created. Because applySettings defaults to true, this happens unless it is explicitly disabled.
This store-specific behavior can create a missing index and change settings during repository creation. Set applySettings = false when index creation and settings are managed separately.
Built-in Repository Methods
The built-in repository methods do not all use the same Meilisearch API:
-
findById(…)andexistsById(…)use direct document lookup;findAllById(…)uses native ID-list retrieval. -
findAll()lists all documents in one document-list request. SortedfindAll(Sort)counts first, then fetches up to that count in one sorted request. -
A paged
findAll(Pageable)uses search APIs. An unpagedPageableuses document listing, with the same sorted-listing behavior when a sort is supplied. -
count()reads the index total from a document-list request with a zero-document limit; it does not run a search. -
Writes and deletes delegate to document-oriented operations in
MeilisearchOperations.
pagination.maxTotalHits limits search-backed reads, not document-backed listing.
Both unsorted and sorted document listings use POST /documents/fetch without an explicit fields list.
Document reads ignore displayedAttributes and require documents.get permission.
Method Behavior at a Glance
| Repository method family | Backing behavior |
|---|---|
|
Uses direct document lookup after converting the repository id through the configured converter. |
|
Uses native ID-list retrieval, available from Meilisearch 1.14; there is no fallback on older servers. Missing IDs are omitted, and the returned entities retain the requested ID order. |
|
Lists all documents in one document-list request and materializes the result in memory. |
|
Counts documents, then makes one sorted document-list request limited to that count and materializes the full list in memory. Sorting requires Meilisearch 1.16 or later and attributes configured as sortable. Concurrent additions may be absent from the result. |
|
A paged |
|
Gets the document total through the operations layer; |
|
Delegates to |
Paging and Totals
findAll(Pageable) selects its backing API based on whether the Pageable is paged.
A paged request uses BasicQuery plus search result metadata. Its Page total comes from the total reported by Meilisearch search results, not a separate count request. The default pagination.maxTotalHits value is 1000; a configured cap can limit search content even when the reported total is larger. For example, a search can report 11 matching documents while returning only 10 hits.
An unpaged request returns all retrieved documents in memory and sets the Page total to the retrieved document count. It is not capped by maxTotalHits. Supplying a sort makes the document-list path count first and fetch up to that count; additions between the count and fetch may be absent.
The search-backed Page does not expose richer search response data such as facet or federation metadata. Call MeilisearchOperations directly from the service layer when you need those Meilisearch-specific results.