java_small_white Created with Sketch.

Getting Started

Supported platforms

This API client only suports Java 1.8+. If you need support for older version, please use this package.

Install

If you’re using Maven, add the following dependency to your pom.xml file:

<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch</artifactId>
  <version>[2,]</version>
</dependency>

For the asynchronous version use:

<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-async</artifactId>
  <version>[2,]</version>
</dependency>

On Google AppEngine use this:

<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-appengine</artifactId>
  <version>[2,]</version>
</dependency>

Philosophy

Builder

The v2 of the api client uses a builder to create the APIClient object:

  • on Google App Engine use the AppEngineAPIClientBuilder
    • if you fancy Future, use the AsyncHttpAPIClientBuilder
  • on Android, use the Android API Client
  • on a regular JVM, use the ApacheAPIClientBuilder

JSON & Jackson2

All the serialization/deserialization is done with Jackson2. You can add your custom ObjectMapper with the method setObjectMapper of the builder. Changing it might produce unexpected results. You can find the one used in the interface com.algolia.search.Defaults.DEFAULT_OBJECT_MAPPER.

Async & Future

All methods of the AsyncAPIClient are exactly the same as the APIClient but returns CompletableFuture<?>. All other classes are prefixes with Async. You can also pass an optional ExecutorService to the build of the AsyncHttpAPIClientBuilder.

Init Index

To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.

APIClient client = new ApacheAPIClientBuilder("YourApplicationID", "YourAPIKey").build();

For the asynchronous version:

AsyncAPIClient client = new AsyncHttpAPIClientBuilder("YourApplicationID", "YourAPIKey").build();

For Google AppEngine:

APIClient client = new AppEngineAPIClientBuilder("YourApplicationID", "YourAPIKey").build();

The api key that is displayed here is your ADMIN API Key. To maintain security, never use your ADMIN API Key on your frontend or share it with anyone. In your frontend, use the SEARCH ONLY API Key or any other key that has search only rights.