如果我正确理解了您的意图,那么
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" } } } } } } }}希望这会有所帮助!



