Skip to content

GetSettings doesn't publicly expose the result #8352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
braveyp opened this issue Sep 19, 2024 · 3 comments · Fixed by #8361
Closed

GetSettings doesn't publicly expose the result #8352

braveyp opened this issue Sep 19, 2024 · 3 comments · Fixed by #8361
Labels
8.x Relates to a 8.x client version Area: Client Category: Bug

Comments

@braveyp
Copy link

braveyp commented Sep 19, 2024

Elastic.Clients.Elasticsearch version: 8.15.6

Elasticsearch version: 8.15.0

.NET runtime version: 4.8

Operating system version: Windows 11

Description of the problem including expected versus actual behavior:

GetIndicesSettingsReponse puts the settings into a protected dictionary but doesn't provide a public method to actually access those settings.

Steps to reproduce:

  1. var response = await Client.Indices.GetSettingsAsync(s => s.Indices(indexName));
  2. ???

Expected behavior
I would expect a call to get the settings for an index would return the settings, ideally in a typed IndexSettings object.

@braveyp braveyp added 8.x Relates to a 8.x client version Category: Bug labels Sep 19, 2024
@braveyp
Copy link
Author

braveyp commented Sep 20, 2024

The GetIndicesSettingResponse class seems to be missing the Indices property, ie:

    [System.Text.Json.Serialization.JsonIgnore]
    public IReadOnlyDictionary<IndexName, IndexState> Indices => BackingDictionary;

@braveyp
Copy link
Author

braveyp commented Sep 20, 2024

I ended up using a workaround just to get the settings I need:

public class PartialSettingsState
{
    [JsonPropertyName("settings")]
    public PartialSettings Settings { get; set; }
}

public class PartialSettings
{
    [JsonPropertyName("index")]
    public PartialIndexSettings Index { get; set; }
}

public class PartialIndexSettings
{
    [JsonPropertyName("number_of_replicas")]
    public int? NumberOfReplicas { get; set; }

    [JsonPropertyName("refresh_interval")]
    public Duration? RefreshInterval { get; set; }
}

[TestClass]
public class GetSettingsWorkaround
{
    [TestMethod]
    public async Task GetSettings()
    {
        var indexName = "test";
        var client = TestHelper.GetClient();
        var response = await client.Transport.RequestAsync<StringResponse>(HttpMethod.GET,
                $"{indexName}/_settings/index.number_of_replicas,index.refresh_interval");
        var options = new JsonSerializerOptions()
        {
            NumberHandling = JsonNumberHandling.AllowReadingFromString
        };
        IReadOnlyDictionary<IndexName, PartialSettingsState> indices =
            JsonSerializer.Deserialize<Dictionary<IndexName, PartialSettingsState>>(response.Body, options);
        var settings = indices[indexName].Settings;
    }
}

@flobernd
Copy link
Member

Yes, it seems like the public accessor is missing. This should hopefully be an easy fix 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version Area: Client Category: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants