How to use all the cores of Solr in solrj

1k views Asked by At

I have downloaded solr 5.2.0 and have started using $solr_home/bin/solr start

The Logs stated:

Waiting to see Solr listening on port 8983 [/]
Started Solr server on port 8983 (pid=17330). Happy searching!

Then I visited http://localhost:8983/solr and created a new core using Core Admin / new Core as Core1 ( using solr-5.2.0/server/solr/configsets/data_driven_schema_configs/config for the new core)

Then I have written a java code that indexes a few records

the Code is as follows:

public static void main(String[] args) throws IOException, SolrServerException {

    HttpSolrClient solrClient =  new HttpSolrClient("http://localhost:8983/solr/core1"); //$NON-NLS-1$4
    //HttpSolrClient solrClient =  new HttpSolrClient(args[0]); //$NON-NLS-1$4

    // Empty the database...
    solrClient.deleteByQuery( "*:*" );// delete everything! //$NON-NLS-1$
    System.out.println("cleared"); //$NON-NLS-1$
    ArrayList<SolrInputDocument> docs = new ArrayList<>();

    long starttime = System.currentTimeMillis();
    for (int i = 0; i < 1000000; ++i) { 
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("bat", "book"+i); //$NON-NLS-1$ //$NON-NLS-2$
        doc.addField("id", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
        doc.addField("name", "The Legend of the Hobbit part 1 " + i); //$NON-NLS-1$ //$NON-NLS-2$
        doc.addField("id1", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$
        doc.addField("name1", "The Legend of the Hobbit part 2 " + i); //$NON-NLS-1$ //$NON-NLS-2$
        doc.addField("id2", "book id -" + i); //$NON-NLS-1$ //$NON-NLS-2$

        docs.add(doc);

        if (i % 250000 == 0) {
            solrClient.add(docs);
            System.out.println("added "+ i + "documents"); //$NON-NLS-1$ //$NON-NLS-2$
            docs.clear();
        }
    }
    solrClient.add(docs);
    System.out.println("completed adding to Solr. Now commiting.. Please wait"); //$NON-NLS-1$
    solrClient.commit();
    long endtime = System.currentTimeMillis();
    System.out.println("process completed in "+(endtime-starttime)/1000+" seconds"); //$NON-NLS-1$ //$NON-NLS-2$
}

After running the code , I check http://localhost:8983/solr/#/~cores/core1 and seen 1000000 documents indexed.

Then I added another core (named core2 in similar fashion to core 1 ) and then again ran the job, this time , I saw that core 2 didnot show any documents , only core 1 still showed.

Can anybody suggest how to use both the cores of solr to distribute and store the document so that I can index data faster, My assumption is that If I increase the number of cores, the speed of Indexing should Increase.

Kindly anybody let me know if any one has tried and succedded in utilizing both the cores and seen performance improvement.

Thanks.

1

There are 1 answers

3
Abhijit Bashetti On BEST ANSWER

here in your code it still points to core1.

HttpSolrClient solrClient =  new HttpSolrClient("http://localhost:8983/solr/core1"

In case you want to have the indexex for core2

you need to change here

HttpSolrClient solrClient =  new HttpSolrClient("http://localhost:8983/solr/core2"

after this change try run the job, it will index for the core2.