001, +148022337, new York, John
002, +148022338, Hawaii, Emma
003, +148022339, Florida, Sophia
[Hadoop@localhost bin]$ ./post-c Solr_sample.csv
import java.io.IOException; import org.apache.Solr.client.Solrj.SolrClient; import org.apache.Solr.client.Solrj.SolrQuery; import org.apache.Solr.client.Solrj.SolrServerException; import org.apache.Solr.client.Solrj.impl.HttpSolrClient; import org.apache.Solr.client.Solrj.response.QueryResponse; import org.apache.Solr.common.SolrDocumentList; public class RetrievingData { public static void main(String args[]) throws SolrServerException, IOException { //Preparing the Solr client String urlString = "http://localhost:8983/Solr/my_core"; SolrClient Solr = new HttpSolrClient.Builder(urlString).build(); //Preparing the Solr query SolrQuery query = new SolrQuery(); query.setQuery("*:*"); //Adding the field that has to be retrieved query.addField("*"); //Executing query for data QueryResponse queryResponse = Solr.query(query); //Saving the results of the query SolrDocumentList docs = queryResponse.getResults(); System.out.println(docs); System.out.println(docs.get(0)); System.out.println(docs.get(1)); System.out.println(docs.get(2)); //storing the operations Solr.commit(); } }
[Hadoop@localhost bin]$ javac RetrievingData [Hadoop@localhost bin]$ java RetrievingData
{numFound = 3, start = 0, docs = [SolrDocument{id=001, phone = [+148022337], city = [California], first_name = [Olivia], _version_ = 1547262806014820352}, SolrDocument { id = 002, phone = [+148022338], city = [Hawaii], first_name = [Emma], _version_ = 1547262806026354688}, SolrDocument { id = 003, phone = [+148022339], city = [Florida], first_name = [Sophia], _version_ = 1547262806029500416}]} SolrDocument {id = 004, phone = [+148022337], city = [Texas], first_name = [Emily], _version_ = 1547262806014820352}, SolrDocument { id = 002, phone = [+148022338], city = [Hawaii], first_name = [Emma], _version_ = 1547262806026354688}, SolrDocument { id = 003, phone = [+148022339], city = [Florida], first_name = [Sophia], _version_ = 1547262806029500416}