RestElasticClient implements ElasticClient { @Override public double getVersion() { if (version != null) { return version; } final Pattern pattern = Pattern.compile("(\\d+\\.\\d+)\\.\\d+"); try { final Response response = performRequest("GET", "/", null, true); try (final InputStream inputStream = response.getEntity().getContent()) { Map<String,Object> info = mapper.readValue(inputStream, new TypeReference<Map<String, Object>>() {}); @SuppressWarnings("unchecked") Map<String,Object> ver = (Map<String,Object>) info.getOrDefault("version", Collections.EMPTY_MAP); final Matcher m = pattern.matcher((String) ver.get("number")); if (!m.find()) { version = DEFAULT_VERSION; } else { version = Double.valueOf(m.group(1)); } } } catch (Exception e) { LOGGER.warning("Error getting server version: " + e); version = DEFAULT_VERSION; } return version; } RestElasticClient(RestClient client);  RestElasticClient(RestClient client, RestClient proxyClient, boolean enableRunAs); @Override double getVersion(); @Override List<String> getTypes(String indexName); @Override Map<String, Object> getMapping(String indexName, String type); @Override ElasticResponse search(String searchIndices, String type, ElasticRequest request); @Override ElasticResponse scroll(String scrollId, Integer scrollTime); @Override void clearScroll(Set<String> scrollIds); @Override void close(); @SuppressWarnings("unchecked") static void removeMapping(String parent, String key, Map<String,Object> data, String currentParent);  }
@Test public void testVersion() throws IOException { mockVersion("6.7.8"); final double version = client.getVersion(); assertEquals(6.7, version, 1e-9); }
@Test public void testVersionWithInvalidFormat() throws IOException { mockVersion("6"); final double version = client.getVersion(); assertEquals(RestElasticClient.DEFAULT_VERSION, version, 1e-9); }