public void putMapping(String index, String type, String mapping) throws IOException { logger.debug("put mapping [{}/{}]", index, type); StringEntity entity = new StringEntity(mapping, Charset.defaultCharset()); Response restResponse = client.performRequest( "PUT", "/" + index + "/_mapping/" + type, Collections.emptyMap(), entity); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("put mapping response: {}", responseAsMap); }
public void index(String index, String type, String id, String json) throws IOException { logger.debug("put document [{}/{}/{}]", index, type, id); StringEntity entity = new StringEntity(json, Charset.defaultCharset()); Response restResponse = client.performRequest( "PUT", "/" + index + "/" + type + "/" + id, Collections.emptyMap(), entity); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("put document response: {}", responseAsMap); }
public String findVersion() throws IOException { logger.debug("findVersion()"); String version; Response restResponse = client.performRequest("GET", "/"); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("get server response: {}", responseAsMap); Object oVersion = extractFromPath(responseAsMap, "version").get("number"); version = (String) oVersion; logger.debug("findVersion() -> [{}]", version); return version; }
public void waitForHealthyIndex(String index) throws IOException { logger.debug("wait for yellow health on index [{}]", index); Response restResponse = client.performRequest( "GET", "/_cluster/health/" + index, Collections.singletonMap("wait_for_status", "yellow")); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("health response: {}", responseAsMap); }
public void refresh(String index) throws IOException { logger.debug("refresh index [{}]", index); String path = "/"; if (index != null) { path += index + "/"; } path += "_refresh"; Response restResponse = client.performRequest("POST", path); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("refresh raw response: {}", responseAsMap); }
public boolean isExistingIndex(String index) throws IOException { logger.debug("is existing index [{}]", index); try { Response restResponse = client.performRequest("GET", "/" + index); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("get index metadata response: {}", responseAsMap); return true; } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug("index [{}] does not exist", index); return false; } throw e; } }
public boolean isExistingDocument(String index, String type, String id) throws IOException { logger.debug("is existing doc [{}]/[{}]/[{}]", index, type, id); try { Response restResponse = client.performRequest("GET", "/" + index + "/" + type + "/" + id); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("get document response: {}", responseAsMap); return true; } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug("doc [{}]/[{}]/[{}] does not exist", index, type, id); return false; } throw e; } }
public boolean isExistingType(String index, String type) throws IOException { logger.debug("is existing type [{}]/[{}]", index, type); try { Response restResponse = client.performRequest("GET", "/" + index); Map<String, Object> responseAsMap = JsonUtil.asMap(restResponse); logger.trace("get index metadata response: {}", responseAsMap); Map<String, Object> mappings = extractFromPath(responseAsMap, index, "mappings"); return mappings.containsKey(type); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug("type [{}]/[{}] does not exist", index, type); return false; } throw e; } }