Solrj API/Example for collections

user2250246 picture user2250246 · Dec 10, 2013 · Viewed 7.4k times · Source

We are building a wrapper over Solr using SolrJ.

This wrapper will allow clients to specify a collection name and then interact with that collection for insert/update/query using SolrJ wrapper.

I have been able to do insert/update/query operations, but haven't been able to find any SolrJ API/Example to specify collection names.

Its essential to use SolrJ as clients do not want to write string manipulated Solr queries directly.

Also, we want to use collections so that every client has its own index and remains distinct from other clients' documents.

Can anyone point me to SolrJ collection example/API ?

Answer

Arun picture Arun · Dec 10, 2013
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;

CloudSolrServer server = new CloudSolrServer("localhost:9983");
server.setDefaultCollection("collection1");
SolrInputDocument doc = new SolrInputDocument();
doc.addField( "id", "1234");
doc.addField( "name", "A lovely summer holiday");
server.add(doc);
server.commit();

From Solj documentation : http://wiki.apache.org/solr/Solrj