This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

CAST supports Apache Solr via its com.castsoftware.nosqljava extension. Details about how this support is provided for Java source code is discussed below.

Supported Libraries

LibraryVersionSupported
Apache SolrFrom 1.0 Up to: 9.3

(tick)

Supported Operations

Operations Methods Supported
Insert

org.apache.solr.client.solrj.SolrClient.add

org.apache.solr.client.solrj.SolrClient.addBean

org.apache.solr.client.solrj.SolrServer.add

org.apache.solr.client.solrj.SolrServer.addBean

org.apache.solr.client.solrj.SolrServer.addBeans

Select

org.apache.solr.client.solrj.SolrClient.getById

org.apache.solr.client.solrj.SolrClient.query

org.apache.solr.client.solrj.SolrClient.queryAndStreamResponse

org.apache.solr.client.solrj.SolrServer.query

Delete

org.apache.solr.client.solrj.SolrClient.deleteById

org.apache.solr.client.solrj.SolrClient.deleteByQuery

org.apache.solr.client.solrj.SolrServer.deleteById

org.apache.solr.client.solrj.SolrServer.deleteByQuery

Objects

IconDescription

Java ApacheSolr Client

Java ApacheSolr Index

Java Unknown ApacheSolr Index

All links are created between the caller Java Method objects and Java ApachSolr Index objects:

Link typeMethods Supported
useInsertLink

add

addBean

addBeans

useSelectLink

getById

query

queryAndStreamResponse

useDeleteLink

deleteById

deleteByQuery

What results can you expect?

Some example scenarios are shown below:

ApacheSolr Client

Solr client cloud
public class CoreLevelSolrCRUDExample {

    private static final String SOLR_URL = "http://localhost:8983/solr"; // Solr base URL
    private static final String CORE_NAME = "my_core"; // Replace with your core name

    private static final SolrClient solrClient = new HttpSolrClient.Builder(SOLR_URL).build();

    public static void main(String[] args) {
        CoreLevelSolrCRUDExample solrClient = new CoreLevelSolrCRUDExample();

        // Create a document and add it to Solr core
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", "1");
        document.addField("title", "Sample Document");
        document.addField("content", "This is a sample document content.");

        solrClient.createDocument(document);

        // Read the document by ID
        solrClient.readDocument("1");

        // Update the document's title
        solrClient.updateDocument("1", "Updated Document Title");

        // Read the updated document
        solrClient.readDocument("1");

        // Delete the document by ID
        solrClient.deleteDocument("1");

        // Don't forget to close the SolrClient when done
        solrClient.closeSolrClient();
    }

    public void createDocument(SolrInputDocument document) {
        try {
            UpdateResponse response = solrClient.add(CORE_NAME, document);
            solrClient.commit(CORE_NAME);
            System.out.println("Document created successfully. Response: " + response);
        } catch (IOException e) {
            System.err.println("Error creating document: " + e.getMessage());
        }
    }

Insert Operation

Insert Operation
 public void createDocument(SolrInputDocument document) {
        try {
            UpdateResponse response = solrClient.add(CORE_NAME, document);
            solrClient.commit(CORE_NAME);
            System.out.println("Document created successfully. Response: " + response);
        } catch (IOException e) {
            System.err.println("Error creating document: " + e.getMessage());
        }
    }

Select Operation

Select Operation
 public void readDocument(String documentId) {
        try {
            SolrDocument solrDocument = solrClient.getById(CORE_NAME, documentId);
            System.out.println("Read Document: " + solrDocument);
        } catch (IOException e) {
            System.err.println("Error reading document: " + e.getMessage());
        }
    }

Delete Operation

Delete Operation
public void deleteDocument(String documentId) {
        try {
            UpdateResponse response = solrClient.deleteById(CORE_NAME, documentId);
            solrClient.commit(CORE_NAME);
            System.out.println("Document deleted successfully. Response: " + response);
        } catch (IOException e) {
            System.err.println("Error deleting document: " + e.getMessage());
        }
    }

Known Limitations

  • If the Index/core name is not resolved in the CRUD API, then a link is created with an unknown index object.