@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(true); 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); } }
UpdateRequest req = new UpdateRequest(); req.deleteByQuery("documentId:"documentId); req.setAction(ACTION.COMMIT, false, true);
public UpdateResponse deleteByQuery(String query) throws SolrServerException, IOException { return new UpdateRequest().deleteByQuery( query ).process( this ); }
private void sendDeletes(List deletes) throws SolrServerException, IOException { if (deletes.size() > 0) { UpdateRequest req = new UpdateRequest(); for (Object delete : deletes) { if (delete instanceof String) { req.deleteById((String)delete); // add the delete to the req list } else { String query = ((QueryStringHolder)delete).getQuery(); req.deleteByQuery(query); // add the delete to the req list } } req.setCommitWithin(-1); log(req.process(server)); deletes.clear(); } }
@Override public void clearStorage() throws BackendException { try { if (mode!= Mode.CLOUD) { logger.error("Operation only supported for SolrCloud. Cores must be deleted manually through the Solr API when using HTTP mode."); return; } logger.debug("Clearing storage from Solr: {}", solrClient); final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader(); zkStateReader.forciblyRefreshAllClusterStateSlow(); final ClusterState clusterState = zkStateReader.getClusterState(); for (final String collection : clusterState.getCollectionsMap().keySet()) { logger.debug("Clearing collection [{}] in Solr",collection); // Collection is not dropped because it may have been created externally final UpdateRequest deleteAll = newUpdateRequest(); deleteAll.deleteByQuery("*:*"); solrClient.request(deleteAll, collection); } } catch (final SolrServerException e) { logger.error("Unable to clear storage from index due to server error on Solr.", e); throw new PermanentBackendException(e); } catch (final IOException e) { logger.error("Unable to clear storage from index due to low-level I/O error.", e); throw new PermanentBackendException(e); } catch (final Exception e) { logger.error("Unable to clear storage from index due to general error.", e); throw new PermanentBackendException(e); } }
/** * Deletes documents from the index based on a query, specifying max time before commit * * @param collection the Solr collection to delete the documents from * @param query the query expressing what documents to delete * @param commitWithinMs max time (in ms) before a commit will happen * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server * * @since 5.1 */ public UpdateResponse deleteByQuery(String collection, String query, int commitWithinMs) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.deleteByQuery(query); req.setCommitWithin(commitWithinMs); return req.process(this, collection); }
protected UpdateResponse delQ(SolrClient client, SolrParams params, String... queries) throws IOException, SolrServerException { UpdateRequest ureq = new UpdateRequest(); ureq.setParams(new ModifiableSolrParams(params)); for (String q: queries) { ureq.deleteByQuery(q); } return ureq.process(client); }
private void sendDeletes(List deletes) throws SolrServerException, IOException { if (deletes.size() > 0) { UpdateRequest req = new UpdateRequest(); for (Object delete : deletes) { if (delete instanceof String) { req.deleteById((String)delete); // add the delete to the req list } else { String query = ((QueryStringHolder)delete).getQuery(); req.deleteByQuery(query); // add the delete to the req list } } req.setCommitWithin(-1); log(req.process(server)); deletes.clear(); } }
/** * Deletes documents from the index based on a query, specifying max time before commit * * @param collection the Solr collection to delete the documents from * @param query the query expressing what documents to delete * @param commitWithinMs max time (in ms) before a commit will happen * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server * * @since 5.1 */ public UpdateResponse deleteByQuery(String collection, String query, int commitWithinMs) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.deleteByQuery(query); req.setCommitWithin(commitWithinMs); return req.process(this, collection); }
@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); } }
@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); } }
/** Clear given collection. */ static void clearCollection(String collection, AuthorizedSolrClient client) throws IOException { try { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.setAction(UpdateRequest.ACTION.COMMIT, true, true); updateRequest.deleteByQuery("*:*"); client.process(collection, updateRequest); } catch (SolrServerException e) { throw new IOException(e); } }
updateRequest.deleteByQuery(s);
updateRequest.deleteByQuery(s);
updateRequest.deleteByQuery(s);