Web / Apache Solr Interview questions
How do you connect to Solr using SolrJ?
SolrJ is the official Java client for Solr. For standalone Solr, you typically use Http2SolrClient; for SolrCloud, CloudSolrClient, which is ZooKeeper-aware and can route requests to the right shard leader.
SolrClient client = new Http2SolrClient.Builder("http://localhost:8983/solr/products") .build(); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "sku-101"); doc.addField("name", "Wireless Mouse"); client.add(doc); client.commit();
The same client object can also run queries with SolrQuery and client.query(...), making SolrJ suitable for both indexing and search from Java applications.
More Related questions...