Solr
  1. Solr
  2. SOLR-3920

CloudSolrServer doesn't allow to index multiple collections with one instance of server

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0-BETA
    • Fix Version/s: 4.1, 6.0
    • Component/s: SolrCloud
    • Labels:

      Description

      With one instance of CloudSolrServer I can't add documents to multiple collections, for example:

      @Test
      public void shouldSendToSecondCore() throws Exception {
      	//given
      	try {
      		CloudSolrServer server = new CloudSolrServer("localhost:9983");
      		UpdateRequest commit1 = new UpdateRequest();
      		commit1.setAction(ACTION.COMMIT, true, true);
      		commit1.setParam("collection", "collection1");
      		//this commit is bug's cause
      		commit1.process(server);
      		
      		SolrInputDocument doc = new SolrInputDocument();
      		doc.addField("id", "id");
      		doc.addField("name", "name");
      		
      		UpdateRequest update2 = new UpdateRequest();
      		update2.setParam("collection", "collection2");
      		update2.add(doc);
      		update2.process(server);
      		
      		UpdateRequest commit2 = new UpdateRequest();
      		commit2.setAction(ACTION.COMMIT, true, true);
      		commit2.setParam("collection", "collection2");
      		commit2.process(server);
      
      		SolrQuery q1 = new SolrQuery("id:id");
      		q1.set("collection", "collection1");
      		SolrQuery q2 = new SolrQuery("id:id");
      		q2.set("collection", "collection2");
      		
      		//when
      		QueryResponse resp1 = server.query(q1);
      		QueryResponse resp2 = server.query(q2);
      		
      		//then
      		Assert.assertEquals(0L, resp1.getResults().getNumFound());
      		Assert.assertEquals(1L, resp2.getResults().getNumFound());
      	} finally {
      		CloudSolrServer server1 = new CloudSolrServer("localhost:9983");
      		server1.setDefaultCollection("collection1");
      		server1.deleteByQuery("id:id");
      		server1.commit(true, true);
      		
      		CloudSolrServer server2 = new CloudSolrServer("localhost:9983");
      		server2.setDefaultCollection("collection2");
      		server2.deleteByQuery("id:id");
      		server2.commit(true, true);
      	}
      }
      

      Second update goes to first collection.

        Issue Links

          Activity

          Hide
          Mark Miller added a comment -

          You can set the default collection (a method on the CloudSolrServer) or set the collection per update call (collection param).

          Show
          Mark Miller added a comment - You can set the default collection (a method on the CloudSolrServer) or set the collection per update call (collection param).
          Hide
          Grzegorz Sobczyk added a comment -

          I'm sorry - pasted wrong example
          I wrote test and replaced previous code with it.

          Show
          Grzegorz Sobczyk added a comment - I'm sorry - pasted wrong example I wrote test and replaced previous code with it.
          Hide
          Mark Miller added a comment -

          Hmm...I wonder if it's the caching that was put in...

          I'll try working your test into our unit tests.

          Show
          Mark Miller added a comment - Hmm...I wonder if it's the caching that was put in... I'll try working your test into our unit tests.
          Hide
          Mark Miller added a comment -

          I started hitting this rarely in a test while working on another issue - I added to the test so that it would catch a problem here. Fix coming soon.

          Show
          Mark Miller added a comment - I started hitting this rarely in a test while working on another issue - I added to the test so that it would catch a problem here. Fix coming soon.
          Hide
          Mark Miller added a comment -

          Yeah, the caching is whack if you change up the collection list.

          I've got a test and fix.

          Show
          Mark Miller added a comment - Yeah, the caching is whack if you change up the collection list. I've got a test and fix.
          Hide
          Mark Miller added a comment -

          committed to 4X and 5X

          Show
          Mark Miller added a comment - committed to 4X and 5X
          Hide
          Zaytsev Sergey added a comment -

          Is there a way to do the same with REST method call running SolrCloud? In other words, to pass a collection_name into a URL for update, in a way like this:
          http://localhost:8983/solr/MyCollectionName/update? bla-bla-bla.....

          Thank you very much!

          Show
          Zaytsev Sergey added a comment - Is there a way to do the same with REST method call running SolrCloud? In other words, to pass a collection_name into a URL for update, in a way like this: http://localhost:8983/solr/MyCollectionName/update? bla-bla-bla..... Thank you very much!
          Hide
          Erick Erickson added a comment -

          Please raise questions like this on the Solr user's list, the JIRAs are
          for discussing code changes rather than answering user-level
          questions.

          Especially please refrain from adding to closed JIRAs.

          Of course you can do what you ask. You've used the correct
          syntax already. Did you even try it before posting the question?

          Show
          Erick Erickson added a comment - Please raise questions like this on the Solr user's list, the JIRAs are for discussing code changes rather than answering user-level questions. Especially please refrain from adding to closed JIRAs. Of course you can do what you ask. You've used the correct syntax already. Did you even try it before posting the question?
          Hide
          Zaytsev Sergey added a comment -

          Sorry, I will, definitely.

          And for the subject - of course I did but got no success... That exactly the reason I asked the question...

          Could you please provide the correct syntax ( URL ) to update specific collection ? I'll close this issue instantly then.

          Show
          Zaytsev Sergey added a comment - Sorry, I will, definitely. And for the subject - of course I did but got no success... That exactly the reason I asked the question... Could you please provide the correct syntax ( URL ) to update specific collection ? I'll close this issue instantly then.
          Hide
          Erick Erickson added a comment -

          Try

          http://localhost:8983/solr/collection1/update?stream.body=<commit/>

          That should at least successfully get to your server, tail the log and you should see
          it come through.

          Show
          Erick Erickson added a comment - Try http://localhost:8983/solr/collection1/update?stream.body= <commit/> That should at least successfully get to your server, tail the log and you should see it come through.
          Hide
          Zaytsev Sergey added a comment -

          It seems to work.

          Thanks a lot!

          Show
          Zaytsev Sergey added a comment - It seems to work. Thanks a lot!

            People

            • Assignee:
              Mark Miller
              Reporter:
              Grzegorz Sobczyk
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development