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!

Appendix

This appendix contains reference material for Spring Data Meilisearch.

Schema

Spring Data Meilisearch uses www.vanslog.io/spring/data/meilisearch as its XML namespace URI and resolves the schema from the classpath through Spring’s META-INF/spring.schemas mechanism.

<meilisearch:meilisearch-client>

Creates a MeilisearchClient bean.

When omitted, the XML factory leaves the optional task-wait timeout attributes at 0, unlike the Java builder defaults of 5,000 ms and 50 ms. Set both attributes for applications that save documents or run other task-based operations.

Attribute Default Description

id

Bean id for the client instance.

host-url

localhost:7700

The Meilisearch server URL.

api-key

No authentication

Optional API key. Omit the attribute or set it to an empty string to send requests without authentication. Use a non-empty key for protected instances.

client-agents

Comma-delimited client-agent values sent in the User-Agent header.

request-timeout

0 ms when omitted

Task-completion wait timeout in milliseconds. This is not an HTTP connection timeout.

request-interval

0 ms when omitted

Polling interval in milliseconds while waiting for task completion.

json-handler-ref

jsonHandler

Reference to a bean implementing com.meilisearch.sdk.json.JsonHandler. The XML namespace does not create this bean; declare it yourself.

<meilisearch:repositories>

Enables Meilisearch repository scanning. It extends the generic Spring Data repository namespace and therefore also supports the standard repository namespace attributes.

Attribute Default Description

base-package

Package to scan for repository interfaces.

meilisearch-template-ref

meilisearchTemplate

Reference to the MeilisearchOperations bean used to back discovered repositories.

Example

The example uses MeilisearchTemplate’s one-argument constructor, which creates the default mapping converter and Jackson `ObjectMapper. Wire the converter and mapper explicitly if you need custom conversions.

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:meilisearch="http://www.vanslog.io/spring/data/meilisearch"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.vanslog.io/spring/data/meilisearch
       http://www.vanslog.io/spring/data/meilisearch/spring-meilisearch-1.0.xsd">

    <context:property-placeholder/>

    <bean id="jsonHandler" class="com.meilisearch.sdk.json.GsonJsonHandler"/>

    <meilisearch:meilisearch-client
            id="meilisearchClient"
            host-url="http://localhost:7700"
            api-key="${MEILISEARCH_API_KEY}"
            request-timeout="5000"
            request-interval="50"
            json-handler-ref="jsonHandler"/>

    <bean id="meilisearchTemplate"
          class="io.vanslog.spring.data.meilisearch.client.msc.MeilisearchTemplate">
        <constructor-arg ref="meilisearchClient"/>
    </bean>

    <meilisearch:repositories
            base-package="com.example.movies"
            meilisearch-template-ref="meilisearchTemplate"/>
</beans>