3
votes

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?

1
Put a tab before your line of code to format it as code. - mbomb007
what version of NEST are you using, and what version of Elasticsearch are you targeting? - Russ Cam
This looks like a bug; I've added an issue for it: github.com/elastic/elasticsearch-net/issues/2072 - Russ Cam

1 Answers

0
votes

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