【问题标题】:Retrieving the type names from Elasticsearch Index using Nest使用 Nest 从 Elasticsearch 索引中检索类型名称
【发布时间】:2017-01-13 08:10:26
【问题描述】:

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

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

但是,这只会返回映射的属性,而不是名称。

我的代码有什么遗漏吗?

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

【问题讨论】:

  • 你的意思是,输入名字吗?
  • 是的,类型名称。

标签: c# .net elasticsearch nest


【解决方案1】:

您可以在 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}'");
    }
}

【讨论】:

  • 谢谢,这是为我做的。只是为了澄清,这可以在 Nest 2.3.0 中完成吗?还是只是 2.5.0 中的一个功能?
  • IndexTypeMappings 自 2.3.1 以来一直在 NEST 中,因此无法在 2.3.0 中完成。建议始终将 NEST 更新到您正在使用的主要版本的最新版本,即如果您使用的是 Elasticsearch 2.x,则更新到最新版本的 NEST 2.x
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-29
  • 2021-08-12
  • 2018-05-29
  • 1970-01-01
相关资源
最近更新 更多