简体   繁体   English

使用Nest从Elasticsearch Index检索类型名称

[英]Retrieving the type names from Elasticsearch Index using Nest

This is the code that I'm using to get https://esURL/index-name/_mappings 这是我用来获取https:// esURL / index-name / _mappings的代码

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

However, this only returns the properties of the mappings and not the names. 但是,这仅返回映射的属性,而不返回名称。

Is there something that I am missing with the code? 我的代码中缺少什么吗?

I also wanna add that I'm using Nest 2.5.0. 我还想补充一点,我正在使用Nest 2.5.0。

You can get all of the type names in one or all indices in NEST 2.5.0 with 您可以使用以下方法在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}'");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM