elasticsearch,nest,C#,.net,elasticsearch,Nest" /> elasticsearch,nest,C#,.net,elasticsearch,Nest" />

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

C# 使用Nest从Elasticsearch索引检索类型名称,c#,.net,elasticsearch,nest,C#,.net,elasticsearch,Nest,这是我用来获取的代码 client.GetMapping(mapping=>mapping.Index(“索引名”).AllTypes()) 但是,这只返回映射的属性,而不返回名称 代码中有我遗漏的东西吗 我还想补充一点,我使用的是Nest 2.5.0。您可以使用 var client = new ElasticClient(); // just change .Index() for .AllIndices() for indices var mappings = client.GetMa

这是我用来获取的代码

client.GetMapping(mapping=>mapping.Index(“索引名”).AllTypes())
但是,这只返回映射的属性,而不返回名称

代码中有我遗漏的东西吗


我还想补充一点,我使用的是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}'");
    }
}
var client=new ElasticClient();
//只需将.Index()更改为.AllIndices()即可
var mappings=client.GetMapping(m=>m.Index(“posts”).AllTypes());
foreach(映射中的var索引。IndexTypeMappings)
{
foreach(index.Value中的var类型)
{
//用类型名做些什么
WriteLine($“索引:'{index.Key.Name}',类型:'{type.Key.Name}');
}
}

你是说,类型名称吗?是的,类型名称。谢谢,这是为我做的。为了澄清一下,这可以在Nest 2.3.0中实现吗?或者它只是2.5.0中的一个功能?
IndexTypeMappings
从2.3.1开始就在嵌套中,因此无法在2.3.0中完成。建议始终将NEST更新到您正在使用的主要版本的最新版本,即,如果您使用的是Elasticsearch 2.x,则更新到NEST 2的最新版本。x以下是添加它的提交:
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}'");
    }
}