I have an elasticsearch index with mappings like the following:
{
"indexName": {
"mappings": {
"vault": {
"properties": {
"someMapping": {
"dynamic": "true",
"properties": {
"A": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"B": {
"type": "float"
},
"C": {
"type": "float"
}
}
}
}
}
}
}
}
I need to get the nested mappings' types, for example:
[
{Name = "A", Type = "text"},
{Name = "B", Type = "float"},
{Name = "C", Type = "float"}
]
I need this to happen trough NEST API in .NET Core application.
So far I've tried elasticClient.GetMapping(new GetMappingRequest())
with not much success since I cannot access the nested properties of the field I need (in this example "someMapping")
I was able to achieve what I wanted by the following steps:
allIndicesMappings = elasticClient.GetMapping(new GetMappingRequest()).Mappings
item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "someMapping").Value
That returns the someMapping field, but still we don't have access to it's nested properties. That access we can get by casting it to ObjectProperty
like so:
((ObjectProperty)item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "metadata").Value).Properties
In the Properties
now we have the nested fields and their mappings