private void updateIndexRefresh(String name, Object value) { esClient.admin().indices().prepareUpdateSettings(name).setSettings(ImmutableMap.of("index.refresh_interval", value)).get(); }
private void setIndexSettings(String index, Map<String, Object> settings) { UpdateSettingsResponse response = SHARED_NODE.client().admin().indices() .prepareUpdateSettings(index) .setSettings(settings) .get(); checkState(response.isAcknowledged()); }
public UpdateSettingsRequestBuilder setPreserveExisting(boolean preserveExisting) { request.setPreserveExisting(preserveExisting); return this; } }
@Override protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) { final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest() .indices(concreteIndices) .settings(request.settings()) .setPreserveExisting(request.isPreserveExisting()) .ackTimeout(request.timeout()) .masterNodeTimeout(request.masterNodeTimeout()); updateSettingsService.updateSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() { @Override public void onResponse(ClusterStateUpdateResponse response) { listener.onResponse(new AcknowledgedResponse(response.isAcknowledged())); } @Override public void onFailure(Exception t) { logger.debug(() -> new ParameterizedMessage("failed to update settings on indices [{}]", (Object) concreteIndices), t); listener.onFailure(t); } }); } }
protected void markIndicesReadOnly(Set<String> indicesToMarkReadOnly) { // set read-only block but don't block on the response client.admin().indices().prepareUpdateSettings(indicesToMarkReadOnly.toArray(Strings.EMPTY_ARRAY)). setSettings(Settings.builder().put(IndexMetaData.SETTING_READ_ONLY_ALLOW_DELETE, true).build()).execute(); }
/** * Sets the settings to be updated (either json or yaml format) */ public UpdateSettingsRequestBuilder setSettings(String source, XContentType xContentType) { request.settings(source, xContentType); return this; }
Settings indexSettings = Settings.builder().put("index.number_of_replicas", updateSettings).build(); tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet(); final AcknowledgedResponse response = tc.admin().indices().updateSettings((new UpdateSettingsRequest(index).settings(indexSettings))).actionGet(); System.out.println("Reload config on all nodes"); System.out.println("Update number of replicas to "+(updateSettings) +" with result: "+response.isAcknowledged()); .build(); tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet(); final AcknowledgedResponse response = tc.admin().indices().updateSettings((new UpdateSettingsRequest(index).settings(indexSettings))).actionGet(); System.out.println("Reload config on all nodes"); System.out.println("Auto-expand replicas "+(replicaAutoExpand?"enabled":"disabled"));
@Override public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { return new UpdateSettingsRequestBuilder(this, UpdateSettingsAction.INSTANCE).setIndices(indices); }
/** * A request to update indices settings. * * @param indices The indices to update the settings for. Use {@code null} or {@code _all} to executed against all indices. * @return The request */ public static UpdateSettingsRequest updateSettingsRequest(String... indices) { return new UpdateSettingsRequest(indices); }
/** * Specifies what type of requested indices to ignore and wildcard indices expressions. * <p> * For example indices that don't exist. */ public UpdateSettingsRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; }
/** * Sets the indices the update settings will execute on */ public UpdateSettingsRequestBuilder setIndices(String... indices) { request.indices(indices); return this; }
@Override public UpdateSettingsRequestBuilder newRequestBuilder(ElasticsearchClient client) { return new UpdateSettingsRequestBuilder(client, this); } }
private static void updateSettings(BulkIndexer bulkIndexer, Map<String, Object> settings) { UpdateSettingsRequestBuilder req = bulkIndexer.client.nativeClient().admin().indices().prepareUpdateSettings(bulkIndexer.indexType.getIndex()); req.setSettings(settings); req.get(); } }
/** * Sets the settings to be updated */ public UpdateSettingsRequestBuilder setSettings(Map<String, Object> source) { request.settings(source); return this; }
public UpdateSettingsRequestBuilder(ElasticsearchClient client, UpdateSettingsAction action, String... indices) { super(client, action, new UpdateSettingsRequest(indices)); }
/** * Sets the settings to be updated */ public UpdateSettingsRequestBuilder setSettings(Settings settings) { request.settings(settings); return this; }
/** * Sets the settings to be updated */ public UpdateSettingsRequestBuilder setSettings(Settings.Builder settings) { request.settings(settings); return this; }
public UpdateSettingsRequest fromXContent(XContentParser parser) throws IOException { Map<String, Object> settings = new HashMap<>(); Map<String, Object> bodySettings = parser.map(); Object innerBodySettings = bodySettings.get("settings"); // clean up in case the body is wrapped with "settings" : { ... } if (innerBodySettings instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> innerBodySettingsMap = (Map<String, Object>) innerBodySettings; settings.putAll(innerBodySettingsMap); } else { settings.putAll(bodySettings); } return this.settings(settings); }
@Override protected ClusterBlockException checkBlock(UpdateSettingsRequest request, ClusterState state) { // allow for dedicated changes to the metadata blocks, so we don't block those to allow to "re-enable" it ClusterBlockException globalBlock = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); if (globalBlock != null) { return globalBlock; } if (request.settings().size() == 1 && // we have to allow resetting these settings otherwise users can't unblock an index IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) || IndexMetaData.INDEX_READ_ONLY_SETTING.exists(request.settings()) || IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.settings())) { return null; } return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); }
/** * Sets the settings to be updated (either json or yaml format) */ @SuppressWarnings("unchecked") public UpdateSettingsRequest settings(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); settings(Strings.toString(builder), builder.contentType()); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } return this; }