Search in sources :

Example 21 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.

the class SolrExampleTests method testChineseDefaults.

@Test
public void testChineseDefaults() throws Exception {
    SolrClient client = getSolrClient();
    // Empty the database...
    // delete everything!
    client.deleteByQuery("*:*");
    client.commit();
    // make sure it got in
    assertNumFound("*:*", 0);
    // Beijing medical University
    UpdateRequest req = new UpdateRequest();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "42");
    doc.addField("text", "北京医科大学");
    req.add(doc);
    req.setAction(ACTION.COMMIT, true, true);
    req.process(client);
    // Beijing university should match:
    SolrQuery query = new SolrQuery("北京大学");
    QueryResponse rsp = client.query(query);
    assertEquals(1, rsp.getResults().getNumFound());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ErrorTrackingConcurrentUpdateSolrClient(org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) ContentStreamUpdateRequest(org.apache.solr.client.solrj.request.ContentStreamUpdateRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Test(org.junit.Test)

Example 22 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.

the class MergeIndexesExampleTestBase method setupCores.

private UpdateRequest setupCores() throws SolrServerException, IOException {
    UpdateRequest up = new UpdateRequest();
    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    up.deleteByQuery("*:*");
    up.process(getSolrCore0());
    up.process(getSolrCore1());
    up.clear();
    // Add something to each core
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "AAA");
    doc.setField("name", "core0");
    // Add to core0
    up.add(doc);
    up.process(getSolrCore0());
    // Add to core1
    doc.setField("id", "BBB");
    doc.setField("name", "core1");
    up.add(doc);
    up.process(getSolrCore1());
    // Now Make sure AAA is in 0 and BBB in 1
    SolrQuery q = new SolrQuery();
    QueryRequest r = new QueryRequest(q);
    q.setQuery("id:AAA");
    assertEquals(1, r.process(getSolrCore0()).getResults().size());
    assertEquals(0, r.process(getSolrCore1()).getResults().size());
    assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
    assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
    return up;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 23 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.

the class DistribDocExpirationUpdateProcessorTest method test.

@Test
public void test() throws Exception {
    // some docs with no expiration
    UpdateRequest req1 = new UpdateRequest();
    for (int i = 1; i <= 100; i++) {
        req1.add(sdoc("id", i));
    }
    req1.commit(cluster.getSolrClient(), COLLECTION);
    // this doc better not already exist
    waitForNoResults(0, params("q", "id:999", "rows", "0", "_trace", "sanity_check"));
    // record the indexversion for each server so we can check later
    // that it only changes for one shard
    final Map<String, Long> initIndexVersions = getIndexVersionOfAllReplicas();
    assertTrue("WTF? no versions?", 0 < initIndexVersions.size());
    // add a doc with a short TTL 
    new UpdateRequest().add(sdoc("id", "999", "tTl_s", "+30SECONDS")).commit(cluster.getSolrClient(), COLLECTION);
    // wait for one doc to be deleted
    waitForNoResults(180, params("q", "id:999", "rows", "0", "_trace", "did_it_expire_yet"));
    // verify only one shard changed
    final Map<String, Long> finalIndexVersions = getIndexVersionOfAllReplicas();
    assertEquals("WTF? not same num versions?", initIndexVersions.size(), finalIndexVersions.size());
    final Set<String> nodesThatChange = new HashSet<String>();
    final Set<String> shardsThatChange = new HashSet<String>();
    int coresCompared = 0;
    DocCollection collectionState = cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(COLLECTION);
    for (Replica replica : collectionState.getReplicas()) {
        coresCompared++;
        String name = replica.getName();
        String core = replica.getCoreName();
        Long initVersion = initIndexVersions.get(core);
        Long finalVersion = finalIndexVersions.get(core);
        assertNotNull(name + ": no init version for core: " + core, initVersion);
        assertNotNull(name + ": no final version for core: " + core, finalVersion);
        if (!initVersion.equals(finalVersion)) {
            nodesThatChange.add(core + "(" + name + ")");
            shardsThatChange.add(name);
        }
    }
    assertEquals("Exactly one shard should have changed, instead: " + shardsThatChange + " nodes=(" + nodesThatChange + ")", 1, shardsThatChange.size());
    assertEquals("somehow we missed some cores?", initIndexVersions.size(), coresCompared);
// TODO: above logic verifies that deleteByQuery happens on all nodes, and ...
// doesn't affect searcher re-open on shards w/o expired docs ... can we also verify 
// that *only* one node is sending the deletes ?
// (ie: no flood of redundant deletes?)
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.

the class ShardRoutingTest method doDBQ.

// TODO: refactor some of this stuff into the SolrJ client... it should be easier to use
void doDBQ(String q, String... reqParams) throws Exception {
    UpdateRequest req = new UpdateRequest();
    req.deleteByQuery(q);
    req.setParams(params(reqParams));
    req.process(cloudClient);
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 25 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.

the class TestTlogReplica method testOnlyLeaderIndexes.

public void testOnlyLeaderIndexes() throws Exception {
    createAndWaitForCollection(1, 0, 2, 0);
    CloudSolrClient cloudClient = cluster.getSolrClient();
    new UpdateRequest().add(sdoc("id", "1")).add(sdoc("id", "2")).add(sdoc("id", "3")).add(sdoc("id", "4")).process(cloudClient, collectionName);
    {
        UpdateHandler updateHandler = getSolrCore(true).get(0).getUpdateHandler();
        RefCounted<IndexWriter> iwRef = updateHandler.getSolrCoreState().getIndexWriter(null);
        assertTrue("IndexWriter at leader must see updates ", iwRef.get().hasUncommittedChanges());
        iwRef.decref();
    }
    for (SolrCore solrCore : getSolrCore(false)) {
        RefCounted<IndexWriter> iwRef = solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null);
        assertFalse("IndexWriter at replicas must not see updates ", iwRef.get().hasUncommittedChanges());
        iwRef.decref();
    }
    checkRTG(1, 4, cluster.getJettySolrRunners());
    new UpdateRequest().deleteById("1").deleteByQuery("id:2").process(cloudClient, collectionName);
    // The DBQ is not processed at replicas, so we still can get doc2 and other docs by RTG
    checkRTG(2, 4, getSolrRunner(false));
    new UpdateRequest().commit(cloudClient, collectionName);
    waitForNumDocsInAllActiveReplicas(2);
    // Update log roll over
    for (SolrCore solrCore : getSolrCore(false)) {
        UpdateLog updateLog = solrCore.getUpdateHandler().getUpdateLog();
        assertFalse(updateLog.hasUncommittedChanges());
    }
    // UpdateLog copy over old updates
    for (int i = 15; i <= 150; i++) {
        cloudClient.add(collectionName, sdoc("id", String.valueOf(i)));
        if (random().nextInt(100) < 15 & i != 150) {
            cloudClient.commit(collectionName);
        }
    }
    checkRTG(120, 150, cluster.getJettySolrRunners());
    waitForReplicasCatchUp(20);
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrIndexWriter(org.apache.solr.update.SolrIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) RefCounted(org.apache.solr.util.RefCounted) SolrCore(org.apache.solr.core.SolrCore) UpdateLog(org.apache.solr.update.UpdateLog) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)273 Test (org.junit.Test)151 Tuple (org.apache.solr.client.solrj.io.Tuple)114 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)89 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)88 SolrInputDocument (org.apache.solr.common.SolrInputDocument)75 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)64 ArrayList (java.util.ArrayList)38 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)36 IOException (java.io.IOException)29 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)26 SolrParams (org.apache.solr.common.params.SolrParams)26 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)23 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)21 AbstractUpdateRequest (org.apache.solr.client.solrj.request.AbstractUpdateRequest)21 HashMap (java.util.HashMap)20 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)20 List (java.util.List)19 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18