MeiliSearch | Website | Blog | Twitter | Documentation | FAQ
⚡ Lightning Fast, Ultra Relevant, and Typo-Tolerant Search Engine MeiliSearch client written in Java
MeiliSearch Java is a client for MeiliSearch written in Java. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box.
dependencies {
// add meilisearch core package
implementation 'net.riyazali.meilisearch-java:meili:master-SNAPSHOT'// add default remote and encoder packages (or you could also provide custom implementations!)
implementation 'net.riyazali.meilisearch-java:meili-remote-okhttp:master-SNAPSHOT'
implementation 'net.riyazali.meilisearch-java:meili-encoder-gson:master-SNAPSHOT'
}There are many easy ways to download and run a MeiliSearch instance.
For example, if you use Docker:
$ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKeyNB: you can also download MeiliSearch from Homebrew or APT.
publicfinalclassExample {
publicstaticvoidmain(Stringargs[]) throwsException {
Meiliclient = newMeili(
// uses the default okhttp remote and gson encoderHttpRemote.create("https://meili.example.com:7700", "API_KEY"),
GsonEncoder.create()
);
// get or create an indexIndex<Movie> index = client.index(Movie.class);
// insert new documentsUpdateop = index.insert(newMovie(/*...*/), newMovie(/*...*/));
// add/update/delete operations return an update object // which represents an asynchromous task queued on the meili server// use the returned object to query for the operation's status// see https://docs.meilisearch.com/guides/advanced_guides/asynchronous_updates.html for more// to wait until the update is appliedwhile(!op.done()) {
Thread.sleep(1_000);
op = op.refresh();
}
// to lookup / search an indexSearchPage<Movie> result = index.search("harry pottre"); // meili is typo-tolerant!for(Moviemovie : result) {
// ... cool stuff here ...
}
}
// just add @Document to your model class and you're good to go!@Document(index = "movies", primaryKey = "id")
staticclassMovie {
privateStringid;
// other fields omitted for brevity...
}
}This package is compatible with the following MeiliSearch versions:
v0.10.X
Most of the HTTP routes of MeiliSearch are accessible via methods in this SDK.
You can check out the API documentation.
// index creation is handled automatically by the sdkIndex<Movie> index = client.index(Movie.class); // this will automatically create an index if one doesn't exist// auto creation (while handy) incurs additional round-trip// if you don't want that, you can use the following signatureIndex<Movie> index = client.index(Movie.class, false/* autoCreate */);// use the document's primary key to fetch an instanceMoviemovie = index.get("1234");// add a single documentUpdateop = index.insert(newMovie(/* ... */));
// or many documents at onceUpdateop = index.insert(newMovie(/* .. */), newMovie(/* .. */));// Delete one documentindex.delete(movie);
// Delete several documentsindex.delete(movie0, movie1, movie2);
// Delete all documents /!\index.clear();SearchPage<Movie> result = index.search("prince");All the supported options are described in this documentation section.
SearchPage<Movie> result = index.search(
SearchConfig.builder().query("harry pottre").highlight("title").build()
);