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.
3
votes
What 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.
– user1556622
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
2 Answers
1
votes
Assuming you are talking about a Java client (for both index and search), what you are looking for is called solrj, and you can find its jars under SOLR dist. The API is very simple to use and you can find some examples here
0
votes
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();