@Override public UpdateSettings build() { return new UpdateSettings(this); } }
/** * 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 GetSettings build() { return new GetSettings(this); }
/** * 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); } }
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)); }
public void setReadOnly(String index) { // https://www.elastic.co/guide/en/elasticsearch/reference/2.4/indices-update-settings.html final Map<String, Object> settings = ImmutableMap.of( "index", ImmutableMap.of("blocks", ImmutableMap.of( "write", true, // Block writing. "read", false, // Allow reading. "metadata", false) // Allow getting metadata. ) ); final UpdateSettings request = new UpdateSettings.Builder(settings).addIndex(index).build(); JestUtils.execute(jestClient, request, () -> "Couldn't set index " + index + " to read-only"); }
String body = "{ \"index\" : { " + "\"number_of_replicas\" :50" + ","+ "} }"; UpdateSettings updateSettings = new UpdateSettings.Builder(body).addIndex(index).build();
/** * 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)); }
public void setReadOnly(String index) { // https://www.elastic.co/guide/en/elasticsearch/reference/2.4/indices-update-settings.html final Map<String, Object> settings = ImmutableMap.of( "index", ImmutableMap.of("blocks", ImmutableMap.of( "write", true, // Block writing. "read", false, // Allow reading. "metadata", false) // Allow getting metadata. ) ); final UpdateSettings request = new UpdateSettings.Builder(settings).addIndex(index).build(); JestUtils.execute(jestClient, request, () -> "Couldn't set index " + index + " to read-only"); }
@Override public UpdateSettings build() { return new UpdateSettings(this); } }
/** * 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 GetSettings build() { return new GetSettings(this); }
/** * 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); } }
@Override public UpdateSettings build() { return new UpdateSettings(this); } }
/** * 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 GetSettings build() { return new GetSettings(this); }
/** * 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); } }
@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(); }