elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Cannot clear refresh_interval of Index Setting with null using low level client

Open marcdefaria opened this issue 2 years ago • 2 comments

Java API client version

7.17.1

Java version

8

Elasticsearch Version

7.17.1

Problem description

Using the rest High Level Client, I was able to overwrite the refresh_interval value of an indexSetting to be the default value using the following bit of code:

UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest("accounts-index");
updateSettingsRequest.settings(Settings.builder().put("index.refresh_interval", (String) null));

try {
    restHighLevelClient.indices().putSettings(updateSettingsRequest, RequestOptions.DEFAULT);
}
catch(IOException e) {
    throw new Exception();
}

Using the low level client, I am unable to do so. If I try to run the following bit of code:

IndexSettings indexSettings = IndexSettings.of(is -> is
    .refreshInterval(Time.of(t -> t.time((String) null))));

PutIndicesSettingsRequest putIndicesSettingsRequest = PutIndicesSettingsRequest.of(pisr -> pisr
    .index(singleton("accounts-index"))
    .settings(indexSettings));

try {
    PutIndicesSettingsResponse putIndicesSettingsResponse = esClient.indices()..putSettings(putIndicesSettingsRequest);

    return putIndicesSettingsResponse.acknowledged();
}
catch (IOException e) {
    throw new Exception(e);
}

I get the exception:

co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'Builder.<variant value>'
	at co.elastic.clients.util.ApiTypeHelper.requireNonNull(ApiTypeHelper.java:76)
	at co.elastic.clients.elasticsearch._types.Time.<init>(Time.java:97)
	at co.elastic.clients.elasticsearch._types.Time.<init>(Time.java:57)
	at co.elastic.clients.elasticsearch._types.Time$Builder.build(Time.java:176)
	at co.elastic.clients.elasticsearch._types.Time$Builder.build(Time.java:158)
	at co.elastic.clients.elasticsearch._types.Time.of(Time.java:102)

For now, I have reverted to setting the refresh_interval explicitly to 1 second when I want to set it to the default. I want to however switch back to being able to overwrite the refresh_interval to just be the default without explicitly setting it, ie. by passing null instead of "1s" to the Time parameter.

Is there a way to do this I am missing or is this a bug in the Time object that does not allow passing of null?

marcdefaria avatar May 06 '22 15:05 marcdefaria

I have the same problem, how did you deal with it?

yangxueyong avatar Aug 01 '22 14:08 yangxueyong

@yangxueyong I set the refresh_interval explicitly to 1s as mentioned.

marcdefaria avatar Aug 01 '22 15:08 marcdefaria