You can use SQL Java Database Connectivity (JDBC) to access the search engine service named LindormSearch. This topic describes how to use the open source Solr JDBC to access the LindormSearch service.

Add the Maven dependency

Add the following dependency to the pom.xml file of your Java application:

<dependency>
  <groupId>org.apache.solr</groupId>
  <artifactId>solr-solrj</artifactId>
  <version>7.7.3</version>
</dependency>

Obtain the endpoint to access your cluster

After the LindormSearch service is activated in the Lindorm console, you can choose Instance List > Database Connection > Search Engine. On the Search Engine tab, obtain the endpoint of your cluster.

Endpoints
Note You can use SQL JDBC to access LindormSearch only over private endpoints.

Create an index

You can create a collection on the Cluster Management page. In addition, you can refer to the steps in the document to write test data to the collection.

Example code

import org.apache.solr.client.solrj.io.sql.DriverImpl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class SqlDemo {
  private static String zkHost = "Private endpoint";
  private static String collection = "demoindex";

  static {
    try {
      Class.forName(DriverImpl.class.getName());
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  public static void main(String[] args) throws Exception {
    SqlDemo.run();
  }

  public static void run() throws Exception {
    Connection con = null;
    ResultSet rs = null;
    Statement stmt = null;
    try {
      con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=" + collection);
      stmt = con.createStatement();
      rs = stmt.executeQuery("SELECT id,name_s,age_i FROM " + collection + " ORDER BY age_i desc");

      while(rs.next()) {
        System.out.println(rs.getString("id") + ",name=" + rs.getString("name_s") + ",age=" + rs.getInt("age_i"));
      }
    } catch (Exception e ) {
      e.printStackTrace();
    } finally {
      if (null != rs) {
        rs.close();
      }
      if (null != stmt) {
        stmt.close();
      }
      con.close();
    }
  }
}

You can join the expert service group or submit a ticket to obtain information about other advanced SQL syntax. For more information, see Expert support.