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.
Asked
Active
Viewed 677 times
3
-
1What exactly you don't understand from solrcloud wiki page? Setting up solrcloud or indexing documents into it or how to query solrcloud? Cause solrcloud wiki page is very straight forward and easy to understand. – Dec 26 '12 at 07:07
-
Yes it is very straight forward and clearly understandable.But what I need is an example to integrate solr cloud with java code. Since I am new to Solr, If I get any solr cloud example with java code , it will be useful. – ak87 Jan 02 '13 at 09:36
2 Answers
0
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();

javacreed
- 958
- 1
- 8
- 20