使用 Nest 从 Elasticsearch 索引中检索类型名称

Retrieving the type names from Elasticsearch Index using Nest

这是我用来获取 https://esURL/index-name/_mappings

的代码
client.GetMapping<object>(mapping => mapping.Index("index-name").AllTypes())

但是,这只是 returns 映射的属性,而不是名称。

代码中是否缺少某些内容?

我还想补充一点,我使用的是 Nest 2.5.0。

您可以在 NEST 2.5.0 中获取一个或所有索引中的所有类型名称

var client = new ElasticClient();

// just change .Index() for .AllIndices() for indices
var mappings = client.GetMapping<object>(m => m.Index("posts").AllTypes());

foreach (var index in mappings.IndexTypeMappings)
{
    foreach (var type in index.Value)
    {
        // do something with type names
        Console.WriteLine($"index: '{index.Key.Name}', type: '{type.Key.Name}'");
    }
}