我有一个弹性搜索索引,其映射如下:
{
"indexName": {
"mappings": {
"vault": {
"properties": {
"someMapping": {
"dynamic": "true",
"properties": {
"A": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"B": {
"type": "float"
},
"C": {
"type": "float"
}
}
}
}
}
}
}
}
我需要获取嵌套映射的类型,例如:
[
{Name = "A", Type = "text"},
{Name = "B", Type = "float"},
{Name = "C", Type = "float"}
]
我需要通过 .NET Core 应用程序中的 NEST API 来实现这一点。到目前为止,我尝试过elasticClient.GetMapping(new GetMappingRequest())
并没有取得多大成功,因为我无法访问我需要的字段的嵌套属性(在本例中为“someMapping”)
我能够通过以下步骤实现我想要的:
allIndicesMappings = elasticClient.GetMapping(new GetMappingRequest()).Mappings
item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "someMapping").Value
返回 someMapping 字段,但我们仍然无法访问它的嵌套属性。访问我们可以通过铸造得到它ObjectProperty
,像这样:((ObjectProperty)item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "metadata").Value).Properties
在Properties
现在我们有嵌套字段及其映射本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句