简体   繁体   English

使用NEST客户端获取Elasticsearch类型映射名称

[英]Get Elasticsearch type mapping names with NEST client

With the Nest client version < 2.0, it was possible to get a list of all the type mappings of an index, including the names of the mappings. 使用Nest客户端版本<2.0,可以获得索引的所有类型映射的列表,包括映射的名称。 In Nest version > 2.0, it seems this is not possible. 在Nest版本> 2.0中,似乎这是不可能的。 A list of mappings can be returned, but the names are not included. 可以返回映射列表,但不包括名称。 For example, I am using the following code to get the list of mappings: 例如,我使用以下代码来获取映射列表:

var response = elasticClient.GetMapping<object>(mapping => mapping.Index("index.name").AllTypes());

The raw response from elasticsearch contains the names of mappings, but the response from the Nest client does not. elasticsearch的原始响应包含映射的名称,但Nest客户端的响应却没有。 It only contains the list of properties in the mappings. 它只包含映射中的属性列表。 Any idea how to do this with the Nest client version > 2.0? 任何想法如何使用Nest客户端版本> 2.0?

In 2019 using NEST 6.4.1 with Elasticsearch 5.5, it is possible to list types like this: 在2019年使用NEST 6.4.1和Elasticsearch 5.5,可以列出这样的类型:

var response = client.GetMapping<object>(mapping => mapping.Index(currentIndex).AllTypes());    
IEnumerable<Nest.TypeName> keys = response.Indices.Values.First().Mappings.Keys;

foreach(var key in keys)
{
    Console.WriteLine(key.ToString());
}

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

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