public void waitForShards(String index) throws Exception { restClient.execute(GET, "_cluster/health/" + index + "?level=indices&wait_for_status=yellow"); } }
public void refresh(Resource resource) { execute(POST, resource.refresh()); }
protected Response execute(Method method, String path, boolean checkStatus) { return execute(new SimpleRequest(method, null, path), checkStatus); }
protected Response execute(Method method, String path, ByteSequence buffer) { return execute(new SimpleRequest(method, null, path, null, buffer), true); }
protected Response execute(Method method, String path, ByteSequence buffer, boolean checkStatus) { return execute(new SimpleRequest(method, null, path, null, buffer), checkStatus); }
protected Response execute(Method method, String path, String params, ByteSequence buffer, boolean checkStatus) { return execute(new SimpleRequest(method, null, path, params, buffer), checkStatus); }
protected InputStream execute(Request request) { return execute(request, true).body(); }
protected InputStream execute(Method method, String path) { return execute(new SimpleRequest(method, null, path)); }
protected Response execute(Method method, String path, String params, boolean checkStatus) { return execute(new SimpleRequest(method, null, path, params), checkStatus); }
protected Response execute(Method method, String path, String params, ByteSequence buffer) { return execute(new SimpleRequest(method, null, path, params, buffer), true); }
public void waitForShards() throws Exception { restClient.execute(GET, "_cluster/health?level=indices&wait_for_status=green"); }
protected InputStream execute(Method method, String path, String params) { return execute(new SimpleRequest(method, null, path, params)); }
public <T> T get(String q, String string) { return parseContent(execute(GET, q), string); }
private long countBeforeES5X(String indexAndType, String shardId, QueryBuilder query) { StringBuilder uri = new StringBuilder(indexAndType); uri.append("/_count"); if (StringUtils.hasLength(shardId)) { uri.append("?preference=_shards:"); uri.append(shardId); } Response response = execute(GET, uri.toString(), searchRequest(query)); Number count = (Number) parseContent(response.body(), "count"); return (count != null ? count.longValue() : -1); }
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 void putMapping(String index, String type, byte[] bytes) { // create index first (if needed) - it might return 403/404 touch(index); if (internalVersion.after(EsMajorVersion.V_6_X)) { execute(PUT, index + "/_mapping", new BytesArray(bytes)); } else { execute(PUT, index + "/_mapping/" + type, new BytesArray(bytes)); } }
Scroll scroll(String query, BytesArray body, ScrollReader reader) throws IOException { InputStream scroll = client.execute(POST, query, body).body(); try { return reader.read(scroll); } finally { if (scroll instanceof StatsAware) { stats.aggregate(((StatsAware) scroll).stats()); } } }
public String postDocument(Resource resource, BytesArray document) throws IOException { // If untyped, the type() method returns '_doc' Request request = new SimpleRequest(Method.POST, null, resource.index() + "/" + resource.type(), null, document); Response response = execute(request, true); Object id = parseContent(response.body(), "_id"); if (id == null || !StringUtils.hasText(id.toString())) { throw new EsHadoopInvalidRequest( String.format("Could not determine successful write operation. Request[%s > %s] Response[%s]", request.method(), request.path(), IOUtils.asString(response.body()) ) ); } return id.toString(); }
public boolean touch(String index) { if (!indexExists(index)) { Response response = execute(PUT, index, false); if (response.hasFailed()) { String msg = null; // try to parse the answer try { msg = parseContent(response.body(), "error"); } catch (Exception ex) { // can't parse message, move on } if (StringUtils.hasText(msg) && !msg.contains("IndexAlreadyExistsException")) { throw new EsHadoopIllegalStateException(msg); } } return response.hasSucceeded(); } return false; }
public InputStream scroll(String scrollId) { // NB: dynamically get the stats since the transport can change long start = network.transportStats().netTotalTime; try { BytesArray body; if (internalVersion.onOrAfter(EsMajorVersion.V_2_X)) { body = new BytesArray("{\"scroll_id\":\"" + scrollId + "\"}"); } else { body = new BytesArray(scrollId); } // use post instead of get to avoid some weird encoding issues (caused by the long URL) InputStream is = execute(POST, "_search/scroll?scroll=" + scrollKeepAlive.toString(), body).body(); stats.scrollTotal++; return is; } finally { stats.scrollTotalTime += network.transportStats().netTotalTime - start; } }