使用spring-boot-starter-data-elasticsearch 设置了long,为什么却变成了keyword类型

/ 默认分类 / 没有评论 / 1590浏览

实体类定义属性book_idLong类型,但在调用 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)