实体类定义属性
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)