栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在ElasticSearch / NEST中将单个.NET类型映射到多个嵌套对象类型?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在ElasticSearch / NEST中将单个.NET类型映射到多个嵌套对象类型?

如果我正确理解了您的意图,那么

Entity
对象中只会嵌套对象,不是吗?

您可以尝试对实体对象使用elasticsearch的动态映射功能。我假设实体是一个根对象。

curl -X POST localhost:9200/myindex/entity/_mapping{"dynamic_templates": [    {"nested_data_template": {        "mapping": { "type": "nested" },        "match_mapping_type": "object",        "path_match": "*" }}]}

path_match: *
match_mapping_type: object
表示将对所有以object作为值的字段名称应用嵌套类型映射。

使用NEST和Fluent API,您可以使用以下API。IntelliSense将指导您如何构建上面的映射。;)

descriptor.DynamicTemplates(DynamicTemplatesDescriptor<Entity>)

每次出现与该模板匹配的新属性时,elasticsearch都会基于动态映射更新映射。一段时间后,您的映射将如下所示:

{  "entity": {    "mappings": {      "entity": {        "dynamic_templates": [          { "nested_data_template": {   "mapping": {     "type": "nested"   },   "match_mapping_type": "object",   "path_match": "*" }          }        ],        "properties": {          "test": { "type": "nested", "properties": {   "test": {     "type": "string"   },   "another_property": {     "type": "string"   } }          },          "test1": { "type": "nested", "properties": {   "test": {     "type": "string"   } }          }        }      }    }  }}

希望这会有所帮助!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403652.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号