Expand my Community achievements bar.

AEM Integration with Algolia Search Using Java API

Avatar

Community Advisor

9/20/22

Company Name: Rightpoint

Company URL: https://www.linkedin.com/company/rightpointindia/

Your Name: Nikhil Kumar

Your Title: AEM Lead


As we have already seen so many integration with search servers like Solr and Elastic. Now we have something new as part of enhancing search capability in AEM.
Algolia is really easy to manage and it's really simple to set it up. It provides different API for the connection to the Algolia server.

Below are the list of some API that Algolia supports:
https://www.algolia.com/doc/api-client/getting-started/install/java/?language=java
3743448B-24F2-49DE-9E48-2F0D7E7E88EE.jpeg

Lets start with creating our own Algolia account. It provides a 17 days trial period. So yeah this the enough time to explore all it's features and integrations.

Creating Account:
1. Create you trial account on alogolia.com.
2. After logging in you can create you own index here and start indexing the data using that index name. I have take dev_initial as my index name.

43535EA3-D066-419C-95B5-E8ACE5C5C5C2.jpeg

I am going to use the JAVA Api provided by Algolia.
To use this API we need to add the following dependencies in POM.xml

<!-- Algolia library with Apache HTTP requester (compatible with Java 8 and above) -->
<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-core</artifactId>
  <version>3.10.0</version>
</dependency>
<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-apache</artifactId>
  <version>3.10.0</version>
</dependency>

<!-- Algolia library with JDK 11 native HTTP client (compatible with Java 11 and above) -->
<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-core</artifactId>
  <version>3.10.0</version>
</dependency>
<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-java-net</artifactId>
  <version>3.10.0</version>
</dependency>

<!-- Algolia library with Apache HTTP requester bundled as a single uber JAR (compatible with Java 8 and above) -->
<dependency>
  <groupId>com.algolia</groupId>
  <artifactId>algoliasearch-apache-uber</artifactId>
  <version>3.10.0</version>
</dependency>

After updating the POM.xml file we need to run the mvn compile command to download the dependencies.
Now we have all the dependencies available to integrate AEM with Algolia.

I have used a test servlet to index some random data.

You should have ApplicationID and Admin API Key to connect in AEM , which you can get it on your Algolia account https://www.algolia.com/api-keys
Which will be used in below code snippet:

SearchClient client = 
DefaultSearchClient.create("YourApplicationID", "YourAdminAPIKey");

57D53199-C63C-4000-920E-08E350C22598.jpeg

372DF205-22C6-4D38-A16F-8B5E7A73C461.jpeg

 

 

 

class Contact {

  private String firstname;
  private String lastname;
  private int followers;
  private String company;
  private String objectID;

  // Getters/setters ommitted
}

Note: Before deploying the code deploy the algoliasearch-apache-uber.jar (3.10.0) on the AEM felix console from https://repo1.maven.org/maven2/com/algolia/algoliasearch-apache-uber/3.10.0/

After indexing the data we can see the data is stored at Algolia server for search implementation. It's really easy to manage using the dashboard availability and easy to manage the data on the Algolia server.
295DF0F3-C312-489F-90F7-6C9D3BDC8046.jpeg

 

 

In case of any query you can post your queries on https://discourse.algolia.com/t/com-algolia-search-cannot-be-resolved/10222/12 and get it resolved. Algolia Team gets back to you very quickly.

 

@Jagpreet_Singh_ @kautuk_sahni @VeenaVikraman 

 

 

Aspire Experience Manager Journey Optimizer