Search in sources :

Example 6 with UpdateSettingsRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest in project graylog2-server by Graylog2.

the class ClientES7 method resetIndexBlock.

@Override
public void resetIndexBlock(String index) {
    final UpdateSettingsRequest request = new UpdateSettingsRequest(index).settings(Collections.singletonMap("index.blocks.read_only_allow_delete", null));
    client.execute((c, requestOptions) -> c.indices().putSettings(request, requestOptions), "Unable to reset index block for " + index);
}
Also used : UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 7 with UpdateSettingsRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest in project snow-owl by b2ihealthcare.

the class EsIndexAdmin method updateSettings.

@Override
public void updateSettings(Map<String, Object> newSettings) {
    if (CompareUtils.isEmpty(newSettings)) {
        return;
    }
    // ignore local and/or dynamic settings
    final Set<String> unsupportedDynamicSettings = Sets.difference(Sets.difference(newSettings.keySet(), DYNAMIC_SETTINGS), LOCAL_SETTINGS);
    if (!unsupportedDynamicSettings.isEmpty()) {
        throw new IndexException(String.format("Settings [%s] are not dynamically updateable settings.", unsupportedDynamicSettings), null);
    }
    boolean shouldUpdate = false;
    for (String settingKey : newSettings.keySet()) {
        Object currentValue = settings.get(settingKey);
        Object newValue = newSettings.get(settingKey);
        if (!Objects.equals(currentValue, newValue)) {
            shouldUpdate = true;
        }
    }
    if (!shouldUpdate) {
        return;
    }
    Map<String, Object> esSettings = new HashMap<>(newSettings);
    // remove any local settings from esSettings
    esSettings.keySet().removeAll(LOCAL_SETTINGS);
    for (DocumentMapping mapping : mappings.getMappings()) {
        final String index = getTypeIndex(mapping);
        // if any index exists, then update the settings based on the new settings
        if (exists(mapping)) {
            try {
                log.info("Applying settings '{}' changes in index {}...", esSettings, index);
                AcknowledgedResponse response = client.indices().updateSettings(new UpdateSettingsRequest().indices(index).settings(esSettings));
                checkState(response.isAcknowledged(), "Failed to update index settings '%s'.", index);
            } catch (IOException e) {
                throw new IndexException(String.format("Couldn't update settings of index '%s'", index), e);
            }
        }
    }
    // update both local and es settings
    settings.putAll(newSettings);
}
Also used : Maps.newHashMap(com.google.common.collect.Maps.newHashMap) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IOException(java.io.IOException) DocumentMapping(com.b2international.index.mapping.DocumentMapping)

Example 8 with UpdateSettingsRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest in project sonarqube by SonarSource.

the class EsTester method setIndexSettings.

private void setIndexSettings(String index, Map<String, Object> settings) {
    AcknowledgedResponse response = null;
    try {
        response = ES_REST_CLIENT.nativeClient().indices().putSettings(new UpdateSettingsRequest(index).settings(settings), RequestOptions.DEFAULT);
    } catch (IOException e) {
        throw new IllegalStateException("Could not update index settings", e);
    }
    checkState(response.isAcknowledged());
}
Also used : UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IOException(java.io.IOException)

Example 9 with UpdateSettingsRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest in project sonarqube by SonarSource.

the class IndexCreator method removeReadOnly.

private void removeReadOnly(IndexType.IndexMainType mainType) {
    LOGGER.info("Index [{}] is read-only. Making it writable...", mainType.getIndex().getName());
    String indexName = mainType.getIndex().getName();
    Settings.Builder builder = Settings.builder();
    builder.putNull("index.blocks.read_only_allow_delete");
    client.putSettings(new UpdateSettingsRequest().indices(indexName).settings(builder.build()));
}
Also used : UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) Settings(org.elasticsearch.common.settings.Settings)

Example 10 with UpdateSettingsRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testUpdateSettings.

public void testUpdateSettings() {
    interceptTransportActions(UpdateSettingsAction.NAME);
    UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(randomIndicesOrAliases()).settings(Settings.builder().put("refresh_interval", -1));
    internalCluster().coordOnlyNodeClient().admin().indices().updateSettings(updateSettingsRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(updateSettingsRequest, UpdateSettingsAction.NAME);
}
Also used : UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)

Aggregations

UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)12 Settings (org.elasticsearch.common.settings.Settings)4 IOException (java.io.IOException)3 OpenIndexRequest (org.elasticsearch.action.admin.indices.open.OpenIndexRequest)3 FutureActionListener (io.crate.action.FutureActionListener)2 ArrayList (java.util.ArrayList)2 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)2 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)2 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)2 UpdateSettingsResponse (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse)2 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)2 DocumentMapping (com.b2international.index.mapping.DocumentMapping)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterRerouteRequest (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest)1 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)1