Search in sources :

Example 1 with UpdateRequest

use of org.apache.solr.client.solrj.request.UpdateRequest in project titan by thinkaurelius.

the class SolrIndex method deleteIndividualFieldsFromIndex.

private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException {
    if (fieldDeletions.isEmpty())
        return;
    Map<String, String> fieldDeletes = new HashMap<String, String>(1) {

        {
            put("set", null);
        }
    };
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField(keyIdField, docId);
    StringBuilder sb = new StringBuilder();
    for (IndexEntry fieldToDelete : fieldDeletions) {
        doc.addField(fieldToDelete.field, fieldDeletes);
        sb.append(fieldToDelete).append(",");
    }
    if (logger.isTraceEnabled())
        logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId);
    UpdateRequest singleDocument = newUpdateRequest();
    singleDocument.add(doc);
    solrClient.request(singleDocument, collectionName);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 2 with UpdateRequest

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

the class Solr5Index method clearStorage.

@Override
public void clearStorage() throws BackendException {
    try {
        if (mode != Mode.CLOUD)
            throw new UnsupportedOperationException("Operation only supported for SolrCloud");
        logger.debug("Clearing storage from Solr: {}", solrClient);
        ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
        zkStateReader.updateClusterState();
        ClusterState clusterState = zkStateReader.getClusterState();
        for (String collection : clusterState.getCollections()) {
            logger.debug("Clearing collection [{}] in Solr", collection);
            UpdateRequest deleteAll = newUpdateRequest();
            deleteAll.deleteByQuery("*:*");
            solrClient.request(deleteAll, collection);
        }
    } catch (SolrServerException e) {
        logger.error("Unable to clear storage from index due to server error on Solr.", e);
        throw new PermanentBackendException(e);
    } catch (IOException e) {
        logger.error("Unable to clear storage from index due to low-level I/O error.", e);
        throw new PermanentBackendException(e);
    } catch (Exception e) {
        logger.error("Unable to clear storage from index due to general error.", e);
        throw new PermanentBackendException(e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 3 with UpdateRequest

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

the class Solr5Index method deleteIndividualFieldsFromIndex.

private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException {
    if (fieldDeletions.isEmpty())
        return;
    Map<String, String> fieldDeletes = new HashMap<String, String>(1) {

        {
            put("set", null);
        }
    };
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField(keyIdField, docId);
    StringBuilder sb = new StringBuilder();
    for (IndexEntry fieldToDelete : fieldDeletions) {
        doc.addField(fieldToDelete.field, fieldDeletes);
        sb.append(fieldToDelete).append(",");
    }
    if (logger.isTraceEnabled())
        logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId);
    UpdateRequest singleDocument = newUpdateRequest();
    singleDocument.add(doc);
    solrClient.request(singleDocument, collectionName);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashMap(java.util.HashMap) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) IndexEntry(com.thinkaurelius.titan.diskstorage.indexing.IndexEntry)

Example 4 with UpdateRequest

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

the class RemoteSolrServerProviderIT method canCreateCollections.

private boolean canCreateCollections(String host) throws Exception {
    UpdateRequest req = new UpdateRequest("/admin/collections");
    req.setParam("action", "CREATE");
    String solrCollection = "solr_" + System.nanoTime();
    req.setParam("name", solrCollection);
    req.setParam("numShards", "2");
    req.setParam("replicationFactor", "2");
    req.setParam("collection.configName", "myconf");
    CloudSolrServer cloudSolrServer = new CloudSolrServer(host);
    cloudSolrServer.setZkConnectTimeout(1000);
    NamedList<Object> request = cloudSolrServer.request(req);
    return request != null && request.get("success") != null;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CloudSolrServer(org.apache.solr.client.solrj.impl.CloudSolrServer)

Example 5 with UpdateRequest

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

the class DistribJoinFromCollectionTest method indexDoc.

protected static Integer indexDoc(String collection, int id, String joinField, String matchField, String getField) throws Exception {
    UpdateRequest up = new UpdateRequest();
    up.setCommitWithin(50);
    up.setParam("collection", collection);
    SolrInputDocument doc = new SolrInputDocument();
    Integer docId = new Integer(id);
    doc.addField("id", docId);
    doc.addField("join_s", joinField);
    if (matchField != null)
        doc.addField("match_s", matchField);
    if (getField != null)
        doc.addField("get_s", getField);
    up.add(doc);
    cluster.getSolrClient().request(up);
    return docId;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

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