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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations