protected InputStream execute(Method method, String path, String params) { return execute(new SimpleRequest(method, null, path, params)); }
SimpleRequest routedRequest = new SimpleRequest(request.method(), null, request.path(), request.params(), request.body()); ByteSequence body = routedRequest.body(); if (body != null) { stats.bytesSent += body.length();
protected InputStream execute(Method method, String path) { return execute(new SimpleRequest(method, null, path)); }
SimpleRequest routedRequest = new SimpleRequest(request.method(), null, request.path(), request.params(), request.body()); ByteSequence body = routedRequest.body(); if (body != null) { stats.bytesSent += body.length();
protected Response execute(Method method, String path, String params, boolean checkStatus) { return execute(new SimpleRequest(method, null, path, params), checkStatus); }
SimpleRequest routedRequest = new SimpleRequest(request.method(), null, request.path(), request.params(), request.body()); ByteSequence body = routedRequest.body(); if (body != null) { stats.bytesSent += body.length();
protected Response execute(Method method, String path, String params, ByteSequence buffer) { return execute(new SimpleRequest(method, null, path, params, buffer), true); }
SimpleRequest routedRequest = new SimpleRequest(request.method(), null, request.path(), request.params(), request.body()); ByteSequence body = routedRequest.body(); if (body != null) { stats.bytesSent += body.length();
protected Response execute(Method method, String path, boolean checkStatus) { return execute(new SimpleRequest(method, null, path), checkStatus); }
SimpleRequest routedRequest = new SimpleRequest(request.method(), null, request.path(), request.params(), request.body()); ByteSequence body = routedRequest.body(); if (body != null) { stats.bytesSent += body.length();
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); }
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 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 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; }
@Test public void testTimeout() { Settings testSettings = new TestSettings(); testSettings.setProperty(ConfigurationOptions.ES_HTTP_TIMEOUT, "3s"); String garbageHost = TEST_NET_1 + ":80"; long maxTime = 3000L + 1000L; // 5s plus some buffer long startTime = System.currentTimeMillis(); try { CommonsHttpTransport transport = new CommonsHttpTransport(testSettings, garbageHost); transport.execute(new SimpleRequest(Request.Method.GET, null, "/")); } catch (Exception e) { long endTime = System.currentTimeMillis(); long took = endTime - startTime; assertThat("Connection Timeout not respected", took, Matchers.lessThan(maxTime)); return; } fail("Should not be able to connect to TEST_NET_1"); } }
SimpleRequest request = new SimpleRequest(Request.Method.GET, null, indexAndType + "/_search?size=0", null, query); String response = "{\n" +