Search in sources :

Example 1 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project YCSB by brianfrankcooper.

the class SolrClient method insert.

/**
   * Insert a record in the database. Any field/value pairs in the specified values HashMap will be
   * written into the record with the specified record key.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to insert.
   * @param values
   *          A HashMap of field/value pairs to insert in the record
   * @return Zero on success, a non-zero error code on error. See this class's description for a
   *         discussion of error codes.
   */
@Override
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
    try {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", key);
        for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
            doc.addField(entry.getKey(), entry.getValue());
        }
        UpdateResponse response;
        if (batchMode) {
            response = client.add(table, doc, commitTime);
        } else {
            response = client.add(table, doc);
            client.commit(table);
        }
        return checkStatus(response.getStatus());
    } catch (IOException | SolrServerException e) {
        e.printStackTrace();
    }
    return Status.ERROR;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 2 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project YCSB by brianfrankcooper.

the class SolrClient method delete.

/**
   * Delete a record from the database.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to delete.
   * @return Zero on success, a non-zero error code on error. See this class's description for a
   *         discussion of error codes.
   */
@Override
public Status delete(String table, String key) {
    try {
        UpdateResponse response;
        if (batchMode) {
            response = client.deleteById(table, key, commitTime);
        } else {
            response = client.deleteById(table, key);
            client.commit(table);
        }
        return checkStatus(response.getStatus());
    } catch (IOException | SolrServerException e) {
        e.printStackTrace();
    }
    return Status.ERROR;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 3 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project YCSB by brianfrankcooper.

the class SolrClient method update.

/**
   * Update a record in the database. Any field/value pairs in the specified values HashMap will be
   * written into the record with the specified record key, overwriting any existing values with the
   * same field name.
   *
   * @param table
   *          The name of the table
   * @param key
   *          The record key of the record to write.
   * @param values
   *          A HashMap of field/value pairs to update in the record
   * @return Zero on success, a non-zero error code on error. See this class's description for a
   *         discussion of error codes.
   */
@Override
public Status update(String table, String key, HashMap<String, ByteIterator> values) {
    try {
        SolrInputDocument updatedDoc = new SolrInputDocument();
        updatedDoc.addField("id", key);
        for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
            updatedDoc.addField(entry.getKey(), Collections.singletonMap("set", entry.getValue()));
        }
        UpdateResponse writeResponse;
        if (batchMode) {
            writeResponse = client.add(table, updatedDoc, commitTime);
        } else {
            writeResponse = client.add(table, updatedDoc);
            client.commit(table);
        }
        return checkStatus(writeResponse.getStatus());
    } catch (IOException | SolrServerException e) {
        e.printStackTrace();
    }
    return Status.ERROR;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 4 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project gora by apache.

the class SolrStore method delete.

@Override
public boolean delete(K key) {
    String keyField = mapping.getPrimaryKey();
    try {
        UpdateResponse rsp = server.deleteByQuery(keyField + ":" + escapeQueryKey(key.toString()));
        server.commit();
        LOG.info(rsp.toString());
        return true;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return false;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 5 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.

the class TestInPlaceUpdatesDistrib method addDocAndGetVersion.

@SuppressWarnings("rawtypes")
protected long addDocAndGetVersion(Object... fields) throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    addFields(doc, fields);
    UpdateRequest ureq = new UpdateRequest();
    ureq.setParam("versions", "true");
    ureq.add(doc);
    UpdateResponse resp;
    // send updates to leader, to avoid SOLR-8733
    resp = ureq.process(LEADER);
    long returnedVersion = Long.parseLong(((NamedList) resp.getResponse().get("adds")).getVal(0).toString());
    assertTrue("Due to SOLR-8733, sometimes returned version is 0. Let us assert that we have successfully" + " worked around that problem here.", returnedVersion > 0);
    return returnedVersion;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) NamedList(org.apache.solr.common.util.NamedList)

Aggregations

UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)43 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 IOException (java.io.IOException)13 SolrServerException (org.apache.solr.client.solrj.SolrServerException)12 ArrayList (java.util.ArrayList)10 SolrClient (org.apache.solr.client.solrj.SolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 SolrDocument (org.apache.solr.common.SolrDocument)8 NamedList (org.apache.solr.common.util.NamedList)7 Future (java.util.concurrent.Future)6 Test (org.junit.Test)6 ExecutorService (java.util.concurrent.ExecutorService)5 SolrException (org.apache.solr.common.SolrException)5 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2