((HttpEntityEnclosingRequest) httpUriRequest).setEntity(entityBuilder.build());
((HttpEntityEnclosingRequest) httpUriRequest).setEntity(entityBuilder.build());
@Test public void test() throws Exception { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { HttpPut put = new HttpPut( String.format(URL_TEMPLCATE, PORT, TABLE_NAME.getNameAsString(), ROW, FAMILY, QUALIFIER)); put.setEntity(EntityBuilder.create().setText(VALUE) .setContentType(ContentType.create("text-plain", StandardCharsets.UTF_8)).build()); try (CloseableHttpResponse resp = client.execute(put)) { assertEquals(HttpStatus.SC_OK, resp.getStatusLine().getStatusCode()); } HttpGet get = new HttpGet( String.format(URL_TEMPLCATE, PORT, TABLE_NAME.getNameAsString(), ROW, FAMILY, QUALIFIER)); try (CloseableHttpResponse resp = client.execute(get)) { assertEquals(HttpStatus.SC_OK, resp.getStatusLine().getStatusCode()); assertEquals("value", Bytes.toString(ByteStreams.toByteArray(resp.getEntity().getContent()))); } get = new HttpGet(String.format(URL_TEMPLCATE, PORT, TABLE_NAME.getNameAsString(), "whatever", FAMILY, QUALIFIER)); try (CloseableHttpResponse resp = client.execute(get)) { assertEquals(HttpStatus.SC_NOT_FOUND, resp.getStatusLine().getStatusCode()); } } } }
@Override public void performLowLevelRequest(String method, String endpoint, String jsonEntity) throws IOException { HttpEntity entity = EntityBuilder.create().setText(jsonEntity).setContentType(ContentType.APPLICATION_JSON).build(); lowLevelClient.performRequest(method, endpoint, Collections.emptyMap(), entity); }
/** * Reindex data from one index/type to another index * @param sourceIndex source index name * @param sourceType source type name * @param targetIndex target index name * @return The number of documents that have been reindexed * @throws IOException In case of error */ public int reindex(String sourceIndex, String sourceType, String targetIndex) throws IOException { logger.debug("reindex [{}]/[{}] -> [{}]/[doc]", sourceIndex, sourceType, targetIndex); String reindexQuery = "{ \"source\": {\n" + " \"index\": \"" + sourceIndex + "\",\n" + " \"type\": \"" + sourceType + "\"\n" + " },\n" + " \"dest\": {\n" + " \"index\": \"" + targetIndex + "\",\n" + " \"type\": \"doc\"\n" + " }\n" + "}\n"; logger.trace("{}", reindexQuery); HttpEntity entity = EntityBuilder.create().setText(reindexQuery).setContentType(ContentType.APPLICATION_JSON).build(); Response restResponse = lowLevelClient.performRequest("POST", "/_reindex", Collections.emptyMap(), entity); Map<String, Object> response = asMap(restResponse); logger.debug("reindex response: {}", response); return (response == null ? -1 : (int) response.get("total")); }
/** * Fully removes a type from an index (removes data) * @param index index name * @param type type * @throws IOException In case of error */ public void deleteByQuery(String index, String type) throws IOException { logger.debug("deleteByQuery [{}]/[{}]", index, type); String deleteByQuery = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " }\n" + "}"; HttpEntity entity = EntityBuilder.create().setText(deleteByQuery).setContentType(ContentType.APPLICATION_JSON).build(); Response restResponse = lowLevelClient.performRequest("POST", "/" + index + "/" + type + "/_delete_by_query", Collections.emptyMap(), entity); Map<String, Object> response = asMap(restResponse); logger.debug("reindex response: {}", response); }
public HttpEntity createEntity(String json) { if (isNullOrEmpty(json)) { return null; } return EntityBuilder.create().setText(json).setContentType(ContentType.APPLICATION_JSON).build(); } }
byte[] data = Files.readAllBytes(path); request.addHeader("X-Goog-Upload-Content-Length", String.valueOf(data.length)); request.setEntity(EntityBuilder.create().setBinary(data).build());
@Override public Response call() throws Exception { return esClientProvider.getClient().performRequest( POST_ACTION, getDeleteByQueryPath(typeDescriptor), Collections.<String, String>emptyMap(), EntityBuilder.create().setText(MAPPER.writeValueAsString(queryMap)).build(), new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString())); } }, typeDescriptor.getIndex(), "DELETE BY QUERY");
@Override public Response call() throws Exception { return esClientProvider.getClient().performRequest( PUT_ACTION, getIndexPath(indexName), Collections.<String, String>emptyMap(), EntityBuilder.create().setText(MAPPER.writeValueAsString(indexSettings)).build(), new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString())); }
@Override public Response call() throws Exception { return esClientProvider.getClient().performRequest( PUT_ACTION, getMappingPath(typeDescriptor), Collections.<String, String>emptyMap(), EntityBuilder.create().setText(MAPPER.writeValueAsString(mapping)).build(), new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString())); } }, typeDescriptor.getIndex(), "PUT MAPPING");
@Override public Response call() throws Exception { return esClientProvider.getClient().performRequest( GET_ACTION, getSearchPath(typeDescriptor), Collections.<String, String>emptyMap(), EntityBuilder.create().setText(MAPPER.writeValueAsString(queryMap)).build(), new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString())); }
protected HttpEntity getJsonEntity(Object o) { return EntityBuilder.create() .setText(GsonUtil.get().toJson(o)) .setContentType(ContentType.APPLICATION_JSON) .build(); }
@Override public void performLowLevelRequest(String method, String endpoint, String jsonEntity) throws IOException { HttpEntity entity = EntityBuilder.create().setText(jsonEntity).setContentType(ContentType.APPLICATION_JSON).build(); lowLevelClient.performRequest(method, endpoint, Collections.emptyMap(), entity); }
public HttpEntity createEntity(String json) { if (isNullOrEmpty(json)) { return null; } return EntityBuilder.create().setText(json).setContentType(ContentType.APPLICATION_JSON).build(); } }
private static final String postBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPost httpPost = new HttpPost(url); httpPost.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPost); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPost.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPost); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String postBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPost httpPost = new HttpPost(url); httpPost.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPost); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPost.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPost); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String putBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String putBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
@Override public HttpEntity getEntity() { return EntityBuilder.create().setText(getXmlBody().asXML()) .setContentType(ContentType.APPLICATION_XML).build(); } }