实体类定义属性
book_id
为Long
类型,但在调用spring-data-elasticsearch:2.5.14.RELEASE
中的createMapping()方法时却被转换成了
keyword`类型
查看createMapping
方法,源码可以发现最终调用最下边的重载方法
IndexOperations.createMapping();
AbstractDefaultIndexOperations.createMapping();
AbstractDefaultIndexOperations.createMapping(Class<?> clazz);
AbstractDefaultIndexOperations.buildMapping(Class<?> clazz)
//构建属性映射
MappingBuilder.buildPropertyMapping(Class<?> clazz)
// 具体的properties解析,为根对象非nested对象
MappingBuilder.mapEntity(XContentBuilder builder, @Nullable ElasticsearchPersistentEntity<?> entity, boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, @Nullable Field parentFieldAnnotation, @Nullable DynamicMapping dynamicMapping);
MappingBuilder.buildPropertyMapping(XContentBuilder builder, boolean isRootObject, ElasticsearchPersistentProperty property)
//判断是否是带有@Id注解或者是字段名是否是 id或者document ,如果满足条件这是主键字段
ElasticsearchPersistentProperty.isIdProperty()
//如果是主键字段则类型设置为keyword
MappingBuilder.applyDefaultIdFieldMapping(XContentBuilder builder, ElasticsearchPersistentProperty property)
本文由 小马哥 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2022/12/27 16:41