public boolean delete(String indexOrType) { Request req = new SimpleRequest(DELETE, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); } public boolean deleteScroll(String scrollId) {
private void checkResponse(Request request, Response response) { if (response.hasFailed()) { // check error first String msg = null; // try to parse the answer try { EsHadoopException ex = errorExtractor.extractError(this.<Map> parseContent(response.body(), null)); msg = (ex != null) ? ex.toString() : null; if (response.isClientError()) { msg = msg + "\n" + request.body(); } else { msg = errorExtractor.prettify(msg, request.body()); } } catch (Exception ex) { // can't parse message, move on } if (!StringUtils.hasText(msg)) { msg = String.format("[%s] on [%s] failed; server[%s] returned [%s|%s:%s]", request.method().name(), request.path(), response.uri(), response.status(), response.statusDescription(), IOUtils.asStringAlways(response.body())); } throw new EsHadoopInvalidRequest(msg); } }
private boolean exists(String indexOrType) { Request req = new SimpleRequest(HEAD, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
protected Response executeNotFoundAllowed(Request req) { Response res = execute(req, false); switch (res.status()) { case HttpStatus.OK: break; case HttpStatus.NOT_FOUND: break; default: checkResponse(req, res); } return res; }
public boolean deleteScroll(String scrollId) { BytesArray body; if (internalVersion.onOrAfter(EsMajorVersion.V_2_X)) { body = new BytesArray(("{\"scroll_id\":[\"" + scrollId + "\"]}").getBytes(StringUtils.UTF_8)); } else { body = new BytesArray(scrollId.getBytes(StringUtils.UTF_8)); } Request req = new SimpleRequest(DELETE, null, "_search/scroll", body); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
public List<List<Map<String, Object>>> targetShards(String index, String routing) { List<List<Map<String, Object>>> shardsJson = null; // https://github.com/elasticsearch/elasticsearch/issues/2726 String target = index + "/_search_shards"; if (routing != null) { target += "?routing=" + HttpEncodingTools.encode(routing); } if (indexReadMissingAsEmpty) { Request req = new SimpleRequest(GET, null, target); Response res = executeNotFoundAllowed(req); if (res.status() == HttpStatus.OK) { shardsJson = parseContent(res.body(), "shards"); } else { shardsJson = Collections.emptyList(); } } else { shardsJson = get(target, "shards"); } return shardsJson; }
/** * Executes a single bulk operation against the provided resource, using the passed data as the request body. * This method will retry bulk requests if the entire bulk request fails, but will not retry singular * document failures. * * @param resource target of the bulk request. * @param data bulk request body. This body will be cleared of entries on any successful bulk request. * @return a BulkActionResponse object that will detail if there were failing documents that should be retried. */ public BulkActionResponse bulk(Resource resource, TrackingBytesArray data) { // NB: dynamically get the stats since the transport can change long start = network.transportStats().netTotalTime; Response response = execute(PUT, resource.bulk(), data); long spent = network.transportStats().netTotalTime - start; stats.bulkTotal++; stats.docsSent += data.entries(); stats.bulkTotalTime += spent; // bytes will be counted by the transport layer return new BulkActionResponse(parseBulkActionResponse(response), response.status(), spent); }
protected Response executeNotFoundAllowed(Request req) { Response res = execute(req, false); switch (res.status()) { case HttpStatus.OK: break; case HttpStatus.NOT_FOUND: break; default: checkResponse(req, res); } return res; }
public boolean delete(String indexOrType) { Request req = new SimpleRequest(DELETE, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); } public boolean deleteScroll(String scrollId) {
protected Response executeNotFoundAllowed(Request req) { Response res = execute(req, false); switch (res.status()) { case HttpStatus.OK: break; case HttpStatus.NOT_FOUND: break; default: checkResponse(req, res); } return res; }
public boolean delete(String indexOrType) { Request req = new SimpleRequest(DELETE, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); } public boolean deleteScroll(String scrollId) {
public boolean delete(String indexOrType) { Request req = new SimpleRequest(DELETE, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); } public boolean deleteScroll(String scrollId) {
private boolean exists(String indexOrType) { Request req = new SimpleRequest(HEAD, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
public boolean exists(String indexOrType) { Request req = new SimpleRequest(HEAD, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
protected Response executeNotFoundAllowed(Request req) { Response res = execute(req, false); switch (res.status()) { case HttpStatus.OK: break; case HttpStatus.NOT_FOUND: break; default: checkResponse(req, res); } return res; }
public boolean delete(String indexOrType) { Request req = new SimpleRequest(DELETE, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); } public boolean deleteScroll(String scrollId) {
private boolean exists(String indexOrType) { Request req = new SimpleRequest(HEAD, null, indexOrType); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
public boolean deleteScroll(String scrollId) { BytesArray body; if (internalVersion.onOrAfter(EsMajorVersion.V_2_X)) { body = new BytesArray(("{\"scroll_id\":[\"" + scrollId + "\"]}").getBytes(StringUtils.UTF_8)); } else { body = new BytesArray(scrollId.getBytes(StringUtils.UTF_8)); } Request req = new SimpleRequest(DELETE, null, "_search/scroll", body); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
public boolean deleteScroll(String scrollId) { Request req = new SimpleRequest(DELETE, null, "_search/scroll", new BytesArray(scrollId.getBytes(StringUtils.UTF_8))); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }
public boolean deleteScroll(String scrollId) { BytesArray body; if (internalVersion.onOrAfter(EsMajorVersion.V_2_X)) { body = new BytesArray(("{\"scroll_id\":[\"" + scrollId + "\"]}").getBytes(StringUtils.UTF_8)); } else { body = new BytesArray(scrollId.getBytes(StringUtils.UTF_8)); } Request req = new SimpleRequest(DELETE, null, "_search/scroll", body); Response res = executeNotFoundAllowed(req); return (res.status() == HttpStatus.OK ? true : false); }