All Products
Document Center

Lindorm:Call Apache Solr API operations to access LindormSearch

Last Updated:Jan 05, 2024

This topic describes how to call the Java API operations of open source Apache Solr to access LindormSearch and provides examples.


  • JDK 1.6 or later is installed on a host.

  • The IP address of your client is added to the whitelist of your Lindorm instance. For more information, see Configure whitelists.

Usage notes

Apache Solr API operations cannot be used to access LindormSearch over the Internet.

Step 1: Download solr-solrj

Add a Maven dependency. If you create a project in a Maven repository, add the solr-solrj dependency to the pom.xml file. Example:


Step 2: Create and initialize an instance

  • If you use the HttpSolrClient mode to access LindormSearch, contact the technical support (DingTalk ID: s0s3eg3) to obtain the VPC endpoint of LindormSearch over HTTP (httpUrl). The following code provides an example on how to use the HttpSolrClient mode to access LindormSearch:

        String httpUrl = "http://***:****/solr/";
        HttpSolrClient solrClient = new HttpSolrClient.Builder(httpUrl).build();
  • The following code provides an example on how to use the CloudSolrClient mode to access LindormSearch:

        String zkHost = "ld-bp16cf8611a4r*******/solr"
        CloudSolrClient solrClient = new CloudSolrClient.Builder(Collections.singletonList(zkHost), 
    • CloudSolrClient ensures thread safety and allows multiple threads of an application to share the same object.

    • In the preceding example, zkHost is the LindormSearch endpoint for Solr. For more information about how to obtain the endpoint, see View endpoints.

Step 3: Access LindormSearch

  1. The following code provides an example on how to write data:

        List docs = new ArrayList<>();
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", 1);
        doc.addField("name_s", "bob");
        doc.addField("age_i", 18);
  2. The following code provides an example on how to query data:

        SolrQuery solrQuery = new SolrQuery("name_s:bob");
        QueryResponse response = solrClient.query("your_index", solrQuery);
        SolrDocumentList documentList = response.getResults();
        for(SolrDocument doc : documentList){
            String id = (String)doc.getFieldValue("id");
            //do something

    For more information about sample code that shows how to query data, see Sample code.