Updating index settings by key-value pair

In the new elasticsearch-java api client, is it possible to update a specific index setting by a key-value pair?

Say, you have these keys:

    static final String NUMBER_OF_REPLICAS_KEY = "index.number_of_replicas";
    static final String REFRESH_INTERVAL_KEY = "index.refresh_interval";

Then you create something like

key = REFRESH_INTERVAL_KEY
value = 1200

It seems not possible with the below code

     PutIndicesSettingsRequest request = PutIndicesSettingsRequest.of(b -> b.index(indexName));
      final Map<String, Object> map = new HashMap<>();
      map.put(key, value);

      

Then call

    client.indices().putSettings(...)

Is it possible?

Hi @ALX_DM

One way I know is the one below. Using a Map I don't know if it's possible.

    IndexSettings indexSettings = IndexSettings.of(is -> is.numberOfReplicas("2").refreshInterval(Time.of(t -> t.time("1s"))));
    PutIndicesSettingsRequest request = PutIndicesSettingsRequest.of(b -> b.index("idx_name").settings(indexSettings));
    var response = ClientUtils.getClient().indices().putSettings(request);

@RabBit_BR

I see.

HLRC can do it, but the new es api client cannot for now. Got it :+1:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.