mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
v0.9.50
1.调整注解名称 2.修复1处geoShape不能通过shapeId检索的缺陷
This commit is contained in:
parent
72684f98c3
commit
dd356c322a
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import java.lang.annotation.Target;
|
|||||||
**/
|
**/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(value = {ElementType.FIELD, ElementType.ANNOTATION_TYPE})
|
@Target(value = {ElementType.FIELD, ElementType.ANNOTATION_TYPE})
|
||||||
public @interface TableField {
|
public @interface IndexField {
|
||||||
/**
|
/**
|
||||||
* 自定义字段在es中的名称
|
* 自定义字段在es中的名称
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@ import java.lang.annotation.Target;
|
|||||||
**/
|
**/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
public @interface TableId {
|
public @interface IndexId {
|
||||||
/**
|
/**
|
||||||
* 字段值
|
* 字段值
|
||||||
*
|
*
|
||||||
@ -16,7 +16,7 @@ import java.lang.annotation.Target;
|
|||||||
**/
|
**/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
||||||
public @interface TableName {
|
public @interface IndexName {
|
||||||
/**
|
/**
|
||||||
* 实体对应的索引名
|
* 实体对应的索引名
|
||||||
*
|
*
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.easyes.core.biz;
|
package cn.easyes.core.biz;
|
||||||
|
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.common.enums.FieldStrategy;
|
import cn.easyes.common.enums.FieldStrategy;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
import cn.easyes.core.config.GlobalConfig;
|
import cn.easyes.core.config.GlobalConfig;
|
||||||
@ -85,7 +85,7 @@ public class EntityFieldInfo {
|
|||||||
* @param field 字段
|
* @param field 字段
|
||||||
* @param tableField 字段注解
|
* @param tableField 字段注解
|
||||||
*/
|
*/
|
||||||
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field, TableField tableField) {
|
public EntityFieldInfo(GlobalConfig.DbConfig dbConfig, Field field, IndexField tableField) {
|
||||||
this.column = field.getName();
|
this.column = field.getName();
|
||||||
|
|
||||||
// 优先使用单个字段注解,否则使用全局配置
|
// 优先使用单个字段注解,否则使用全局配置
|
||||||
|
|||||||
@ -305,7 +305,14 @@ public class WrapperProcessor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeoShapeQueryBuilder builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getGeometry());
|
// 构造查询参数
|
||||||
|
GeoShapeQueryBuilder builder;
|
||||||
|
if (StringUtils.isNotBlank(geoParam.getIndexedShapeId())) {
|
||||||
|
builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getIndexedShapeId());
|
||||||
|
} else {
|
||||||
|
builder = QueryBuilders.geoShapeQuery(geoParam.getField(), geoParam.getGeometry());
|
||||||
|
}
|
||||||
|
|
||||||
Optional.ofNullable(geoParam.getShapeRelation()).ifPresent(builder::relation);
|
Optional.ofNullable(geoParam.getShapeRelation()).ifPresent(builder::relation);
|
||||||
Optional.ofNullable(geoParam.getBoost()).ifPresent(builder::boost);
|
Optional.ofNullable(geoParam.getBoost()).ifPresent(builder::boost);
|
||||||
return builder;
|
return builder;
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.easyes.core.toolkit;
|
package cn.easyes.core.toolkit;
|
||||||
|
|
||||||
import cn.easyes.annotation.HighLight;
|
import cn.easyes.annotation.HighLight;
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.annotation.TableId;
|
import cn.easyes.annotation.IndexId;
|
||||||
import cn.easyes.annotation.TableName;
|
import cn.easyes.annotation.IndexName;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
import cn.easyes.common.enums.IdType;
|
import cn.easyes.common.enums.IdType;
|
||||||
import cn.easyes.common.params.DefaultNestedClass;
|
import cn.easyes.common.params.DefaultNestedClass;
|
||||||
@ -21,7 +21,6 @@ import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
|
|||||||
import com.alibaba.fastjson.serializer.NameFilter;
|
import com.alibaba.fastjson.serializer.NameFilter;
|
||||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -256,7 +255,7 @@ public class EntityInfoHelper {
|
|||||||
boolean hasAnnotation = false;
|
boolean hasAnnotation = false;
|
||||||
|
|
||||||
// 初始化封装TableField注解信息
|
// 初始化封装TableField注解信息
|
||||||
if (field.isAnnotationPresent(TableField.class)) {
|
if (field.isAnnotationPresent(IndexField.class)) {
|
||||||
initTableFieldAnnotation(dbConfig, entityInfo, field, fieldList);
|
initTableFieldAnnotation(dbConfig, entityInfo, field, fieldList);
|
||||||
hasAnnotation = true;
|
hasAnnotation = true;
|
||||||
}
|
}
|
||||||
@ -281,7 +280,7 @@ public class EntityInfoHelper {
|
|||||||
*/
|
*/
|
||||||
private static void initTableFieldAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
private static void initTableFieldAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
||||||
Field field, List<EntityFieldInfo> fieldList) {
|
Field field, List<EntityFieldInfo> fieldList) {
|
||||||
TableField tableField = field.getAnnotation(TableField.class);
|
IndexField tableField = field.getAnnotation(IndexField.class);
|
||||||
if (tableField.exist()) {
|
if (tableField.exist()) {
|
||||||
// 存在字段处理
|
// 存在字段处理
|
||||||
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field, tableField);
|
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field, tableField);
|
||||||
@ -381,7 +380,7 @@ public class EntityInfoHelper {
|
|||||||
allFields.forEach(field -> {
|
allFields.forEach(field -> {
|
||||||
String mappingColumn;
|
String mappingColumn;
|
||||||
// 处理TableField注解
|
// 处理TableField注解
|
||||||
TableField tableField = field.getAnnotation(TableField.class);
|
IndexField tableField = field.getAnnotation(IndexField.class);
|
||||||
if (Objects.isNull(tableField)) {
|
if (Objects.isNull(tableField)) {
|
||||||
mappingColumn = getMappingColumn(dbConfig, field);
|
mappingColumn = getMappingColumn(dbConfig, field);
|
||||||
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field);
|
EntityFieldInfo entityFieldInfo = new EntityFieldInfo(dbConfig, field);
|
||||||
@ -464,7 +463,7 @@ public class EntityInfoHelper {
|
|||||||
*/
|
*/
|
||||||
private static boolean initTableIdWithAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
private static boolean initTableIdWithAnnotation(GlobalConfig.DbConfig dbConfig, EntityInfo entityInfo,
|
||||||
Field field) {
|
Field field) {
|
||||||
TableId tableId = field.getAnnotation(TableId.class);
|
IndexId tableId = field.getAnnotation(IndexId.class);
|
||||||
if (tableId != null) {
|
if (tableId != null) {
|
||||||
// 主键策略( 注解 > 全局 )
|
// 主键策略( 注解 > 全局 )
|
||||||
// 设置 Sequence 其他策略无效
|
// 设置 Sequence 其他策略无效
|
||||||
@ -523,7 +522,7 @@ public class EntityInfoHelper {
|
|||||||
*/
|
*/
|
||||||
public static boolean isExistTableId(List<Field> list) {
|
public static boolean isExistTableId(List<Field> list) {
|
||||||
for (Field field : list) {
|
for (Field field : list) {
|
||||||
TableId tableId = field.getAnnotation(TableId.class);
|
IndexId tableId = field.getAnnotation(IndexId.class);
|
||||||
if (tableId != null) {
|
if (tableId != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -552,7 +551,7 @@ public class EntityInfoHelper {
|
|||||||
private static void initTableName(Class<?> clazz, GlobalConfig globalConfig, EntityInfo entityInfo) {
|
private static void initTableName(Class<?> clazz, GlobalConfig globalConfig, EntityInfo entityInfo) {
|
||||||
// 数据库全局配置
|
// 数据库全局配置
|
||||||
GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
|
GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig();
|
||||||
TableName table = clazz.getAnnotation(TableName.class);
|
IndexName table = clazz.getAnnotation(IndexName.class);
|
||||||
String tableName = clazz.getSimpleName().toLowerCase(Locale.ROOT);
|
String tableName = clazz.getSimpleName().toLowerCase(Locale.ROOT);
|
||||||
String tablePrefix = dbConfig.getTablePrefix();
|
String tablePrefix = dbConfig.getTablePrefix();
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
<relativePath>../easy-es-parent</relativePath>
|
<relativePath>../easy-es-parent</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es-parent</artifactId>
|
<artifactId>easy-es-parent</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
|
|
||||||
<name>easy-es-parent</name>
|
<name>easy-es-parent</name>
|
||||||
<description>easy use for elastic search</description>
|
<description>easy use for elastic search</description>
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easy-es</artifactId>
|
<artifactId>easy-es</artifactId>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.easyes.sample.entity;
|
package cn.easyes.sample.entity;
|
||||||
|
|
||||||
import cn.easyes.annotation.HighLight;
|
import cn.easyes.annotation.HighLight;
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.annotation.TableId;
|
import cn.easyes.annotation.IndexId;
|
||||||
import cn.easyes.annotation.TableName;
|
import cn.easyes.annotation.IndexName;
|
||||||
import cn.easyes.common.constants.Analyzer;
|
import cn.easyes.common.constants.Analyzer;
|
||||||
import cn.easyes.common.enums.FieldStrategy;
|
import cn.easyes.common.enums.FieldStrategy;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
@ -18,12 +18,12 @@ import lombok.experimental.Accessors;
|
|||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@TableName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true)
|
@IndexName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true)
|
||||||
public class Document {
|
public class Document {
|
||||||
/**
|
/**
|
||||||
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.CUSTOMIZE)
|
@IndexId(type = IdType.CUSTOMIZE)
|
||||||
private String id;
|
private String id;
|
||||||
/**
|
/**
|
||||||
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
||||||
@ -33,37 +33,37 @@ public class Document {
|
|||||||
* 文档内容,指定了类型及存储/查询分词器
|
* 文档内容,指定了类型及存储/查询分词器
|
||||||
*/
|
*/
|
||||||
@HighLight(mappingField = "highlightContent")
|
@HighLight(mappingField = "highlightContent")
|
||||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
|
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
|
||||||
private String content;
|
private String content;
|
||||||
/**
|
/**
|
||||||
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
||||||
*/
|
*/
|
||||||
@TableField(strategy = FieldStrategy.NOT_EMPTY)
|
@IndexField(strategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String creator;
|
private String creator;
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
@IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||||
private String gmtCreate;
|
private String gmtCreate;
|
||||||
/**
|
/**
|
||||||
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@IndexField(exist = false)
|
||||||
private String notExistsField;
|
private String notExistsField;
|
||||||
/**
|
/**
|
||||||
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.GEO_POINT)
|
@IndexField(fieldType = FieldType.GEO_POINT)
|
||||||
private String location;
|
private String location;
|
||||||
/**
|
/**
|
||||||
* 图形(例如圆心,矩形)
|
* 图形(例如圆心,矩形)
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.GEO_SHAPE)
|
@IndexField(fieldType = FieldType.GEO_SHAPE)
|
||||||
private String geoLocation;
|
private String geoLocation;
|
||||||
/**
|
/**
|
||||||
* 自定义字段名称
|
* 自定义字段名称
|
||||||
*/
|
*/
|
||||||
@TableField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
@IndexField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||||
private String customField;
|
private String customField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easy-es</artifactId>
|
<artifactId>easy-es</artifactId>
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>easy-es-test</artifactId>
|
<artifactId>easy-es-test</artifactId>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package cn.easyes.test.entity;
|
package cn.easyes.test.entity;
|
||||||
|
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.annotation.TableName;
|
import cn.easyes.annotation.IndexName;
|
||||||
import cn.easyes.common.constants.Analyzer;
|
import cn.easyes.common.constants.Analyzer;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
import cn.easyes.common.params.JoinField;
|
import cn.easyes.common.params.JoinField;
|
||||||
@ -13,7 +13,7 @@ import lombok.Data;
|
|||||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
@TableName(child = true)
|
@IndexName(child = true)
|
||||||
public class Comment {
|
public class Comment {
|
||||||
/**
|
/**
|
||||||
* 评论id
|
* 评论id
|
||||||
@ -22,11 +22,11 @@ public class Comment {
|
|||||||
/**
|
/**
|
||||||
* 评论内容
|
* 评论内容
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||||
private String commentContent;
|
private String commentContent;
|
||||||
/**
|
/**
|
||||||
* 父子关系字段
|
* 父子关系字段
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.JOIN)
|
@IndexField(fieldType = FieldType.JOIN)
|
||||||
private JoinField joinField;
|
private JoinField joinField;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package cn.easyes.test.entity;
|
package cn.easyes.test.entity;
|
||||||
|
|
||||||
import cn.easyes.annotation.HighLight;
|
import cn.easyes.annotation.HighLight;
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.annotation.TableId;
|
import cn.easyes.annotation.IndexId;
|
||||||
import cn.easyes.annotation.TableName;
|
import cn.easyes.annotation.IndexName;
|
||||||
import cn.easyes.common.constants.Analyzer;
|
import cn.easyes.common.constants.Analyzer;
|
||||||
import cn.easyes.common.enums.FieldStrategy;
|
import cn.easyes.common.enums.FieldStrategy;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
@ -21,12 +21,12 @@ import java.util.List;
|
|||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@TableName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true, childClass = Comment.class)
|
@IndexName(shardsNum = 3, replicasNum = 2, keepGlobalPrefix = true, childClass = Comment.class)
|
||||||
public class Document {
|
public class Document {
|
||||||
/**
|
/**
|
||||||
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
* es中的唯一id,如果你想自定义es中的id为你提供的id,比如MySQL中的id,请将注解中的type指定为customize或直接在全局配置文件中指定,如此id便支持任意数据类型)
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.CUSTOMIZE)
|
@IndexId(type = IdType.CUSTOMIZE)
|
||||||
private String id;
|
private String id;
|
||||||
/**
|
/**
|
||||||
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
* 文档标题,不指定类型默认被创建为keyword类型,可进行精确查询
|
||||||
@ -36,37 +36,37 @@ public class Document {
|
|||||||
* 文档内容,指定了类型及存储/查询分词器
|
* 文档内容,指定了类型及存储/查询分词器
|
||||||
*/
|
*/
|
||||||
@HighLight(mappingField = "highlightContent",fragmentSize = 2)
|
@HighLight(mappingField = "highlightContent",fragmentSize = 2)
|
||||||
@TableField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
@IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||||
private String content;
|
private String content;
|
||||||
/**
|
/**
|
||||||
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
* 作者 加@TableField注解,并指明strategy = FieldStrategy.NOT_EMPTY 表示更新的时候的策略为 创建者不为空字符串时才更新
|
||||||
*/
|
*/
|
||||||
@TableField(strategy = FieldStrategy.NOT_EMPTY, fieldType = FieldType.KEYWORD_TEXT)
|
@IndexField(strategy = FieldStrategy.NOT_EMPTY, fieldType = FieldType.KEYWORD_TEXT)
|
||||||
private String creator;
|
private String creator;
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
@IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
|
||||||
private String gmtCreate;
|
private String gmtCreate;
|
||||||
/**
|
/**
|
||||||
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
* es中实际不存在的字段,但模型中加了,为了不和es映射,可以在此类型字段上加上 注解@TableField,并指明exist=false
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@IndexField(exist = false)
|
||||||
private String notExistsField;
|
private String notExistsField;
|
||||||
/**
|
/**
|
||||||
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
* 地理位置经纬度坐标 例如: "40.13933715136454,116.63441990026217"
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.GEO_POINT)
|
@IndexField(fieldType = FieldType.GEO_POINT)
|
||||||
private String location;
|
private String location;
|
||||||
/**
|
/**
|
||||||
* 图形(例如圆心,矩形)
|
* 图形(例如圆心,矩形)
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.GEO_SHAPE)
|
@IndexField(fieldType = FieldType.GEO_SHAPE)
|
||||||
private String geoLocation;
|
private String geoLocation;
|
||||||
/**
|
/**
|
||||||
* 自定义字段名称
|
* 自定义字段名称
|
||||||
*/
|
*/
|
||||||
@TableField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
@IndexField(value = "wu-la", fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
|
||||||
private String customField;
|
private String customField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,12 +80,12 @@ public class Document {
|
|||||||
/**
|
/**
|
||||||
* 嵌套类型 注意,务必像下面示例一样指定类型为nested及其nested class,否则会导致框架无法正常运行
|
* 嵌套类型 注意,务必像下面示例一样指定类型为nested及其nested class,否则会导致框架无法正常运行
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.NESTED, nestedClass = User.class)
|
@IndexField(fieldType = FieldType.NESTED, nestedClass = User.class)
|
||||||
private List<User> users;
|
private List<User> users;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父子类型 须通过注解在父文档及子文档的实体类中指明其类型为Join,及其父名称和子名称
|
* 父子类型 须通过注解在父文档及子文档的实体类中指明其类型为Join,及其父名称和子名称
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.JOIN, parentName = "document", childName = "comment")
|
@IndexField(fieldType = FieldType.JOIN, parentName = "document", childName = "comment")
|
||||||
private JoinField joinField;
|
private JoinField joinField;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package cn.easyes.test.entity;
|
package cn.easyes.test.entity;
|
||||||
|
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.annotation.TableName;
|
import cn.easyes.annotation.IndexName;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -25,9 +25,9 @@ import lombok.NoArgsConstructor;
|
|||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName("faq")
|
@IndexName("faq")
|
||||||
public class Faq {
|
public class Faq {
|
||||||
@TableField("faq_name")
|
@IndexField("faq_name")
|
||||||
private String faqName;
|
private String faqName;
|
||||||
private String faqAnswer;
|
private String faqAnswer;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package cn.easyes.test.entity;
|
package cn.easyes.test.entity;
|
||||||
|
|
||||||
import cn.easyes.annotation.TableField;
|
import cn.easyes.annotation.IndexField;
|
||||||
import cn.easyes.common.constants.Analyzer;
|
import cn.easyes.common.constants.Analyzer;
|
||||||
import cn.easyes.common.enums.FieldType;
|
import cn.easyes.common.enums.FieldType;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -18,13 +18,13 @@ import java.util.Set;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
@TableField(value = "user_name", analyzer = Analyzer.IK_SMART)
|
@IndexField(value = "user_name", analyzer = Analyzer.IK_SMART)
|
||||||
private String username;
|
private String username;
|
||||||
@TableField(exist = false)
|
@IndexField(exist = false)
|
||||||
private Integer age;
|
private Integer age;
|
||||||
/**
|
/**
|
||||||
* 多级嵌套
|
* 多级嵌套
|
||||||
*/
|
*/
|
||||||
@TableField(fieldType = FieldType.NESTED, nestedClass = Faq.class)
|
@IndexField(fieldType = FieldType.NESTED, nestedClass = Faq.class)
|
||||||
private Set<Faq> faqs;
|
private Set<Faq> faqs;
|
||||||
}
|
}
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.easy-es</groupId>
|
<groupId>cn.easy-es</groupId>
|
||||||
<artifactId>easy-es</artifactId>
|
<artifactId>easy-es</artifactId>
|
||||||
<version>0.9.40</version>
|
<version>0.9.50</version>
|
||||||
|
|
||||||
<name>easy-es</name>
|
<name>easy-es</name>
|
||||||
<description>easy use for elastic search</description>
|
<description>easy use for elastic search</description>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user