简体   繁体   中英

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. In Nest version > 2.0, it seems this is not possible. 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. It only contains the list of properties in the mappings. Any idea how to do this with the Nest client version > 2.0?

In 2019 using NEST 6.4.1 with Elasticsearch 5.5, it is possible to list types like this:

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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