|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data Meilisearch 0.10.0! |
Operations
Spring Data Meilisearch exposes template-style APIs through MeilisearchOperations.
That interface combines document operations, search operations, access to instance-level APIs, and access to index-scoped APIs.
Entry Point
MeilisearchConfiguration registers a bean named meilisearchOperations and meilisearchTemplate.
Inject that bean when you want direct access to Meilisearch-specific operations instead of the repository abstraction. This is also the primary entry point for store-specific capabilities that are intentionally not surfaced through repositories.
@RestController
class MovieController {
private final MeilisearchOperations operations;
MovieController(MeilisearchOperations operations) {
this.operations = operations;
}
@PostMapping("/movies")
Movie save(@RequestBody Movie movie) {
return operations.save(movie);
}
}
Document Operations
DocumentOperations covers id-oriented access to one mapped entity type:
-
save(T)andsave(List<T>) -
get(String, Class<T>) -
multiGet(…) -
exists(String, Class<?>) -
delete(…) -
deleteAll(Class<?>)
These methods are appropriate when you already know the target document ids and want direct document-style access.
Search Operations
SearchOperations covers full-text and search-oriented APIs:
-
search(query, entityType)for single-index search. -
multiSearch(queries, entityType)for batched non-federated search. -
multiSearch(queries, federation, entityType)for federated multi-search. -
facetSearch(query, entityType)for facet search results. -
similarSearch(query, entityType)for similar-document search. -
count(entityType)for search-backed counting.
BasicQuery query = BasicQuery.builder()
.withQ("Wonder Woman")
.withFilter(new String[] { "genres = Action" })
.build();
SearchHits<Movie> result = operations.search(query, Movie.class);
List<Movie> movies = result.getSearchHits().stream()
.map(SearchHit::getContent)
.toList();
Query Types
Spring Data Meilisearch ships several query value types:
-
BasicQueryfor standard search. -
IndexQueryfor multi-index and federated multi-search scenarios. -
FacetQueryfor facet search. -
SimilarQueryfor similar-document search.
IndexQuery adds indexUid and optional federation options.
SimilarQuery requires both the source documentId and the configured embedder name.
Search Result Types
Search methods return SearchHits<T>.
Each hit is a SearchHit<T> that contains:
-
the mapped entity content,
-
processing time,
-
query text,
-
optional facet statistics and facet distribution,
-
optional federation metadata.
SearchHits#getTotalHits() is accompanied by getTotalHitsRelation():
-
EQUAL_TOmeans the total hit count reflects the exact matching result set reported by Meilisearch. -
OFFmeans exact total-hit metadata is unavailable.
Use the hit list size for the current page content and total-hit metadata only when the relation is EQUAL_TO.
When you need access to raw search metadata such as facets or federation details, prefer MeilisearchOperations directly instead of adapting repository return types.
Kotlin Extensions
Spring Data Meilisearch provides Kotlin extension functions for the blocking operations APIs that take an entity Class argument.
These extensions use reified type parameters so Kotlin callers can omit explicit ::class.java arguments.
val movie = operations.get<Movie>("movie-1")
val hits = operations.search<Movie>(query)
val count = operations.count<Movie>()
val index = operations.indexOps<Movie>()
operations.applySettings<Movie>()
The extensions are thin wrappers over the existing Java contracts. They do not change blocking execution behavior and do not add reactive or coroutine repository support.
Notes on Search Semantics
-
Federated multi-search does not support
Pageablesettings inside the individual queries. Use federationlimitandoffsetinstead. -
Similar-document search requires a compatible embedder already configured in the target index.
-
Repository methods such as
findAll(Pageable)are layered on top of these search operations, so search settings such as pagination limits can influence reported page totals.