elastic / elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html
Apache License 2.0
14 stars 1.15k forks source link

GetSettings doesn't publicly expose the result #8352

Closed braveyp closed 2 months ago

braveyp commented 2 months ago

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 commented 2 months ago

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

    [System.Text.Json.Serialization.JsonIgnore]
    public IReadOnlyDictionary<IndexName, IndexState> Indices => BackingDictionary;
braveyp commented 2 months ago

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 commented 2 months ago

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