簡體   English   中英

使用Nest從Elasticsearch Index檢索類型名稱

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

這是我用來獲取https:// esURL / index-name / _mappings的代碼

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

但是,這僅返回映射的屬性,而不返回名稱。

我的代碼中缺少什么嗎?

我還想補充一點,我正在使用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}'");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM