Reputation: 161
I need some inputs for Solr Cloud integration with java. I read wiki.apache.org/solr/SolrCloud page. I got a basic knowledge. But what I need is to implement a very basic java application with solr cloud with shards and zookeeper and distributed indexing. I have google it. But I can't understand any. Please give me some inputs for creating an app with distributed indexing. Thanks in advance.
Upvotes: 3
Views: 682
Reputation: 968
This is a sample piece of code for indexing the documents to solr server. I believe it is very easy to understand. To run it you need to have the solrj library in your project. For solr cloud you can used a cloudserver instead of the httpsolrserver.
I would suggest you to read the documentation. It is very simple and easy to understand.
SolrServer server = new HttpSolrServer("http://HOST:8983/solr/");
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField( "id", "id1", 1.0f );
doc1.addField( "name", "doc1", 1.0f );
doc1.addField( "price", 10 );
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField( "id", "id2", 1.0f );
doc2.addField( "name", "doc2", 1.0f );
doc2.addField( "price", 20 );
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
docs.add( doc1 );
docs.add( doc2 );
Add the documents to Solr
server.add( docs );
Do a commit
server.commit();
Upvotes: 0