private UpdateRequest newUpdateRequest() { UpdateRequest req = new UpdateRequest(); if(waitSearcher) { req.setAction(UpdateRequest.ACTION.COMMIT, true, true); } return req; }
private void index(boolean isSolrCloud, String collection, Long commitWithin, String contentStreamPath, MultiMapSolrParams requestParams, List<SolrInputDocument> inputDocumentList) throws IOException, SolrServerException,SolrException { UpdateRequest request = new UpdateRequest(contentStreamPath); request.setParams(new ModifiableSolrParams()); // add the extra params, don't use 'set' in case of repeating params Iterator<String> paramNames = requestParams.getParameterNamesIterator(); while (paramNames.hasNext()) { String paramName = paramNames.next(); for (String paramValue : requestParams.getParams(paramName)) { request.getParams().add(paramName, paramValue); } } // specify the collection for SolrCloud if (isSolrCloud) { request.setParam(COLLECTION_PARAM_NAME, collection); } if (commitWithin != null && commitWithin > 0) { request.setParam(COMMIT_WITHIN_PARAM_NAME, commitWithin.toString()); } // if a username and password were provided then pass them for basic auth if (isBasicAuthEnabled()) { request.setBasicAuthCredentials(getUsername(), getPassword()); } request.add(inputDocumentList); UpdateResponse response = request.process(getSolrClient()); getLogger().debug("Got {} response from Solr", new Object[]{response.getStatus()}); inputDocumentList.clear(); }
@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); } }
@Override public SolrRequest toSolrRequest(ITuple tuple) throws SolrMapperException { SolrInputDocument doc = buildDocument(tuple); UpdateRequest request = new UpdateRequest(); request.add(doc); log.debug("Created SolrRequest with content: {}", doc); return request; }
/** * 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); }
public UpdateResponse add(Collection<SolrInputDocument> docs ) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.add(docs); return req.process(this); }
/** * Adds a single document specifying max time before it becomes committed * * @param collection the Solr collection to add the document to * @param doc the input document * @param commitWithinMs max time (in ms) before a commit will happen * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server * * @since solr 5.1 */ public UpdateResponse add(String collection, SolrInputDocument doc, int commitWithinMs) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.add(doc); req.setCommitWithin(commitWithinMs); return req.process(this, collection); }
final UpdateRequest update = new UpdateRequest(); if (!immediateCommit) { update.setCommitWithin(commitWithin); update.add(inputDocument); AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { public Object run() throws IOException, SolrServerException {
protected UpdateResponse add(SolrClient client, SolrParams params, SolrInputDocument... sdocs) throws IOException, SolrServerException { UpdateRequest ureq = new UpdateRequest(); ureq.setParams(new ModifiableSolrParams(params)); for (SolrInputDocument sdoc : sdocs) { ureq.add(sdoc); } return ureq.process(client); }
.get(leaderUrl); if (request == null) { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.setMethod(getMethod()); updateRequest.setCommitWithin(getCommitWithin()); updateRequest.setParams(params); updateRequest.setPath(getPath()); updateRequest.setBasicAuthCredentials(getBasicAuthUser(), getBasicAuthPassword()); updateRequest.setResponseParser(getResponseParser()); request = new LBHttpSolrClient.Req(updateRequest, urls); routes.put(leaderUrl, request); urequest.add(doc, ow); } else { urequest.add(doc); if (request != null) { UpdateRequest urequest = (UpdateRequest) request.getRequest(); urequest.deleteById(deleteId, version); } else { UpdateRequest urequest = new UpdateRequest(); urequest.setParams(params); urequest.deleteById(deleteId, version); urequest.setCommitWithin(getCommitWithin()); urequest.setBasicAuthCredentials(getBasicAuthUser(), getBasicAuthPassword()); request = new LBHttpSolrClient.Req(urequest, urls); routes.put(leaderUrl, request);
/** Inserts the given number of test documents into Solr. */ static void insertTestDocuments(String collection, long numDocs, AuthorizedSolrClient client) throws IOException { List<SolrInputDocument> data = createDocuments(numDocs); try { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.setAction(UpdateRequest.ACTION.COMMIT, true, true); updateRequest.add(data); client.process(collection, updateRequest); } catch (SolrServerException e) { throw new IOException("Failed to insert test documents to collection", e); } }
.get(leaderUrl); if (request == null) { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.setMethod(getMethod()); updateRequest.setCommitWithin(getCommitWithin()); updateRequest.setParams(params); updateRequest.setPath(getPath()); request = new LBHttpSolrClient.Req(updateRequest, urls); routes.put(leaderUrl, request); urequest.add(doc, ow); } else { urequest.add(doc); if (request != null) { UpdateRequest urequest = (UpdateRequest) request.getRequest(); urequest.deleteById(deleteId, version); } else { UpdateRequest urequest = new UpdateRequest(); urequest.setParams(params); urequest.deleteById(deleteId, version); request = new LBHttpSolrClient.Req(urequest, urls); routes.put(leaderUrl, request);
final UpdateRequest updateRequest = new UpdateRequest(); List<List<NamedList>> doclist; List<Entry<SolrInputDocument,Map<Object,Object>>> docMap; sdoc = listToSolrInputDocument((List<NamedList>) o); } else if (o instanceof NamedList) { UpdateRequest req = new UpdateRequest(); req.setParams(new ModifiableSolrParams(((NamedList) o).toSolrParams())); handler.update(null, req, null, null); if(updateRequest.getParams()==null) { NamedList params = (NamedList) namedList[0].get("params"); if(params!=null) { updateRequest.setParams(new ModifiableSolrParams(params.toSolrParams())); updateRequest.deleteById(s); Long version = (Long) params.get(UpdateRequest.VER); if (params.containsKey(ShardParams._ROUTE_)) updateRequest.deleteById(entry.getKey(), (String) params.get(ShardParams._ROUTE_)); else updateRequest.deleteById(entry.getKey(), version); } else { updateRequest.deleteById(entry.getKey()); updateRequest.deleteByQuery(s);
public UpdateResponse commit( boolean waitFlush, boolean waitSearcher ) throws SolrServerException, IOException { return new UpdateRequest().setAction( UpdateRequest.ACTION.COMMIT, waitFlush, waitSearcher ).process( this ); }
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException { if (documents.size() == 0) return; try { solrClient.request(newUpdateRequest().add(documents), collectionName); } catch (HttpSolrClient.RemoteSolrException rse) { logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse); logger.error("Details in failed document batch: "); for (SolrInputDocument d : documents) { Collection<String> fieldNames = d.getFieldNames(); for (String name : fieldNames) { logger.error(name + ":" + d.getFieldValue(name).toString()); } } throw rse; } }
public UpdateResponse deleteById(String id) throws SolrServerException, IOException { return new UpdateRequest().deleteById( id ).process( this ); }
final UpdateRequest updateRequest = new UpdateRequest(); List<List<NamedList>> doclist; List<String> delById; solrInputDocs.add(listToSolrInputDocument(n)); updateRequest.add(solrInputDocs); updateRequest.deleteById(s); updateRequest.deleteByQuery(s);
UpdateRequest req = new UpdateRequest(); req.deleteByQuery("documentId:"documentId); req.setAction(ACTION.COMMIT, false, true);
protected void indexDocs(List<SolrInputDocument> docs) throws IOException, SolrServerException { if (controlClient != null) { UpdateRequest req = new UpdateRequest(); req.add(docs); req.setParam("CONTROL", "TRUE"); req.process(controlClient); } UpdateRequest ureq = new UpdateRequest(); ureq.add(docs); ureq.process(cloudClient); }
/** * Adds the documents supplied by the given iterator. * * @param docIterator the iterator which returns SolrInputDocument instances * * @return the response from the SolrServer */ public UpdateResponse add(Iterator<SolrInputDocument> docIterator) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); req.setDocIterator(docIterator); return req.process(this); }