/** * Check if a given name is an existing alias. * * @param alias Name of the alias to check presence for. * @return {@code true} if alias is an existing alias, {@code false} if it is non-existing or an index. */ public boolean aliasExists(String alias) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(alias).build()); return result.isSucceeded() && !Iterators.contains(result.getJsonObject().fieldNames(), alias); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of alias " + alias, e); } }
public Optional<DateTime> indexCreationDate(String index) { final GetSettings request = new GetSettings.Builder() .addIndex(index) .ignoreUnavailable(true) .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read settings of index " + index); return Optional.of(jestResult.getJsonObject().path(index).path("settings").path("index").path("creation_date")) .filter(JsonNode::isValueNode) .map(JsonNode::asLong) .map(creationDate -> new DateTime(creationDate, DateTimeZone.UTC)); }
assertTrue(result.getErrorMessage(), result.isSucceeded()); GetSettings getSettings = new GetSettings.Builder().addIndex(index).build(); result = client.execute(getSettings); assertTrue(result.getErrorMessage(), result.isSucceeded()); assertTrue(result.getErrorMessage(), result.isSucceeded()); getSettings = new GetSettings.Builder().addIndex(index).build(); result = client.execute(getSettings); assertTrue(result.getErrorMessage(), result.isSucceeded());
/** * Check if a given name is an existing alias. * * @param alias Name of the alias to check presence for. * @return {@code true} if alias is an existing alias, {@code false} if it is non-existing or an index. */ public boolean aliasExists(String alias) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(alias).build()); return result.isSucceeded() && !Iterators.contains(result.getJsonObject().fieldNames(), alias); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of alias " + alias, e); } }
/** * Check if a given name is an existing index. * * @param indexName Name of the index to check presence for. * @return {@code true} if indexName is an existing index, {@code false} if it is non-existing or an alias. */ public boolean exists(String indexName) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(indexName).build()); return result.isSucceeded() && Iterators.contains(result.getJsonObject().fieldNames(), indexName); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of index " + indexName, e); } }
/** * Prefix Query Option allows to include only settings (whose keys) matches the specified prefix. */ public Builder prefixQuery(String prefixQuery) { return setParameter("prefix", prefixQuery); }
@Override public Settings getIndexSettings(String indexName) { GetSettings getSettings = new GetSettings.Builder().addIndex(indexName).build(); JestResult result = jestClientHelper.execute(getSettings); Assert.isTrue(result.isSucceeded(), result.getErrorMessage()); JsonObject json = result.getJsonObject().getAsJsonObject(indexName).getAsJsonObject("settings"); return Settings.builder().loadFromSource(json.toString()).build(); }
public Optional<DateTime> indexCreationDate(String index) { final GetSettings request = new GetSettings.Builder() .addIndex(index) .ignoreUnavailable(true) .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read settings of index " + index); return Optional.of(jestResult.getJsonObject().path(index).path("settings").path("index").path("creation_date")) .filter(JsonNode::isValueNode) .map(JsonNode::asLong) .map(creationDate -> new DateTime(creationDate, DateTimeZone.UTC)); }
/** * Prefix Query Option allows to include only settings (whose keys) matches the specified prefix. */ public Builder prefixQuery(String prefixQuery) { return setParameter("prefix", prefixQuery); }
@Override public Map getSetting(String indexName) { Assert.notNull(indexName, "No index defined for getSettings"); GetSettings.Builder getSettingsBuilder = new GetSettings.Builder(); getSettingsBuilder.addIndex(indexName); JestResult result = execute(getSettingsBuilder.build()); JsonObject entries = result.getJsonObject() .get(indexName).getAsJsonObject() .get("settings").getAsJsonObject() .get("index").getAsJsonObject(); HashMap<String, String> mappings = new HashMap<>(); flatMap("index", entries, mappings); return mappings; }
@Override public Settings getIndexSettings(String indexName) { GetSettings getSettings = new GetSettings.Builder().addIndex(indexName).build(); JestResult result = jestClientHelper.execute(getSettings); Assert.isTrue(result.isSucceeded(), result.getErrorMessage()); JsonObject json = result.getJsonObject().getAsJsonObject(indexName).getAsJsonObject("settings"); return Settings.builder().loadFromSource(json.toString()).build(); }
/** * Prefix Query Option allows to include only settings (whose keys) matches the specified prefix. */ public Builder prefixQuery(String prefixQuery) { return setParameter("prefix", prefixQuery); }
/** * Check if a given name is an existing index. * * @param indexName Name of the index to check presence for. * @return {@code true} if indexName is an existing index, {@code false} if it is non-existing or an alias. */ public boolean exists(String indexName) { try { final JestResult result = jestClient.execute(new GetSettings.Builder().addIndex(indexName).build()); return result.isSucceeded() && Iterators.contains(result.getJsonObject().fieldNames(), indexName); } catch (IOException e) { throw new ElasticsearchException("Couldn't check existence of index " + indexName, e); } }