File tree Expand file tree Collapse file tree 10 files changed +274
-0
lines changed
easy-es-annotation/src/main/java/org/dromara/easyes/annotation
easy-es-test/src/main/java/org/dromara/easyes/test Expand file tree Collapse file tree 10 files changed +274
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .annotation ;
2+
3+ import java .lang .annotation .ElementType ;
4+ import java .lang .annotation .Retention ;
5+ import java .lang .annotation .RetentionPolicy ;
6+ import java .lang .annotation .Target ;
7+
8+ import static org .dromara .easyes .annotation .rely .AnnotationConstants .DEFAULT_JOIN_FIELD_NAME ;
9+
10+ /**
11+ * 父子类型
12+ * <p>
13+ * Copyright © 2024 xpc1024 All Rights Reserved
14+ **/
15+ @ Retention (RetentionPolicy .RUNTIME )
16+ @ Target (ElementType .TYPE )
17+ public @interface Join {
18+ /**
19+ * join字段在es中的名字
20+ *
21+ * @return 索引中的join字段名称 默认为joinField
22+ */
23+ String joinField () default DEFAULT_JOIN_FIELD_NAME ;
24+
25+ /**
26+ * 根节点别名 不指定则默认使用加了当前注解的根类的名称小写作为根节点别名(推荐)
27+ *
28+ * @return 根节点别名
29+ */
30+ String rootAlias () default "" ;
31+
32+ /**
33+ * 非根节点
34+ *
35+ * @return 非根节点列表
36+ */
37+ Node [] nodes () default {};
38+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .annotation ;
2+
3+ import java .lang .annotation .ElementType ;
4+ import java .lang .annotation .Retention ;
5+ import java .lang .annotation .RetentionPolicy ;
6+ import java .lang .annotation .Target ;
7+
8+ /**
9+ * 父子类型
10+ * <p>
11+ * Copyright © 2024 xpc1024 All Rights Reserved
12+ **/
13+ @ Retention (RetentionPolicy .RUNTIME )
14+ @ Target ({ElementType .ANNOTATION_TYPE , ElementType .TYPE })
15+ public @interface Node {
16+ /**
17+ * 父文档别名 非必填,不指定时默认值为parentClass类名小写(推荐)
18+ *
19+ * @return 父文档别名
20+ */
21+ String parentAlias () default "" ;
22+
23+ /**
24+ * 父文档实体类,必填项
25+ *
26+ * @return 父文档实体类
27+ */
28+ Class <?> parentClass ();
29+
30+ /**
31+ * 子文档别名列表,不指定则为子文档类名小写列表(推荐) 若要自定义必须与childClasses数量和顺序一致
32+ *
33+ * @return 子文档别名列表 非必填,默认值为子文档类名小写列表
34+ */
35+ String [] childAliases () default {};
36+
37+ /**
38+ * 子文档实体类列表,必填项
39+ *
40+ * @return 子文档实体类列表
41+ */
42+ Class <?>[] childClasses ();
43+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .annotation ;
2+
3+ import org .dromara .easyes .annotation .rely .DefaultSettingsProvider ;
4+
5+ import java .lang .annotation .ElementType ;
6+ import java .lang .annotation .Retention ;
7+ import java .lang .annotation .RetentionPolicy ;
8+ import java .lang .annotation .Target ;
9+
10+ import static org .dromara .easyes .annotation .rely .AnnotationConstants .*;
11+
12+ /**
13+ * es 索引 settings
14+ * <p>
15+ * Copyright © 2024 xpc1024 All Rights Reserved
16+ **/
17+ @ Retention (RetentionPolicy .RUNTIME )
18+ @ Target (ElementType .TYPE )
19+ public @interface Settings {
20+ /**
21+ * 分片数
22+ *
23+ * @return 默认为1
24+ */
25+ int shardsNum () default DEFAULT_SHARDS ;
26+
27+ /**
28+ * 副本数
29+ *
30+ * @return 默认为1
31+ */
32+ int replicasNum () default DEFAULT_REPLICAS ;
33+
34+ /**
35+ * 默认最大返回数
36+ *
37+ * @return 默认1w条
38+ */
39+ int maxResultWindow () default DEFAULT_MAX_RESULT_WINDOW ;
40+
41+ /**
42+ * 索引的刷新间隔 es默认值为1s ms:表示毫秒 s:表示秒 m:表示分钟
43+ *
44+ * @return 索引的刷新间隔
45+ */
46+ String refreshInterval () default "" ;
47+
48+ /**
49+ * 自定义settings提供类
50+ *
51+ * @return 自定义settings提供类 默认为DefaultSettingsProvider空实现 如需自定义,可继承此类并覆写getSettings方法 将settings信息以Map返回
52+ */
53+ Class <? extends DefaultSettingsProvider > settingsProvider () default DefaultSettingsProvider .class ;
54+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .annotation .rely ;
2+
3+ import java .util .Collections ;
4+ import java .util .Map ;
5+
6+ /**
7+ * es 索引 默认settings 如需拓展须继承此类并覆写getSettings方法提供自定义索引settings实现
8+ * <p>
9+ * Copyright © 2024 xpc1024 All Rights Reserved
10+ **/
11+ public class DefaultSettingsProvider implements ISettingsProvider {
12+ @ Override
13+ public Map <String , Object > getSettings () {
14+ return Collections .emptyMap ();
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .annotation .rely ;
2+
3+ import java .util .Map ;
4+
5+ /**
6+ * es 索引 settings 提供接口
7+ * <p>
8+ * Copyright © 2024 xpc1024 All Rights Reserved
9+ **/
10+ public interface ISettingsProvider {
11+ /**
12+ * 获取settings
13+ *
14+ * @return settingsMap
15+ */
16+ Map <String , Object > getSettings ();
17+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .test .entity ;
2+
3+
4+ import lombok .Data ;
5+ import org .dromara .easyes .annotation .IndexField ;
6+ import org .dromara .easyes .annotation .IndexId ;
7+ import org .dromara .easyes .annotation .rely .FieldType ;
8+
9+
10+ /**
11+ * 作者 数据模型 Document的子文档,Document是其父文档
12+ * <p>
13+ * Copyright © 2024 xpc1024 All Rights Reserved
14+ **/
15+ @ Data
16+ public class Author {
17+ /**
18+ * 作者id
19+ */
20+ @ IndexId
21+ private String authorId ;
22+ /**
23+ * 作者姓名
24+ */
25+ @ IndexField (fieldType = FieldType .KEYWORD )
26+ private String authorName ;
27+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .test .entity ;
2+
3+
4+ import lombok .Data ;
5+ import org .dromara .easyes .annotation .IndexField ;
6+ import org .dromara .easyes .annotation .IndexId ;
7+ import org .dromara .easyes .annotation .rely .FieldType ;
8+
9+
10+ /**
11+ * 联系方式 数据模型 Author的子文档,Author是其父文档,Document是其爷文档
12+ * <p>
13+ * Copyright © 2024 xpc1024 All Rights Reserved
14+ **/
15+ @ Data
16+ public class Contact {
17+ /**
18+ * 联系人id
19+ */
20+ @ IndexId
21+ private String contactId ;
22+ /**
23+ * 地址
24+ */
25+ @ IndexField (fieldType = FieldType .TEXT )
26+ private String address ;
27+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .test .mapper ;
2+
3+
4+ import org .dromara .easyes .annotation .EsDS ;
5+ import org .dromara .easyes .core .core .BaseEsMapper ;
6+ import org .dromara .easyes .test .entity .Author ;
7+
8+ /**
9+ * 父子类型-子文档的mapper
10+ * <p>
11+ * Copyright © 2024 xpc1024 All Rights Reserved
12+ **/
13+ @ EsDS ("ds1" )
14+ public interface AuthorMapper extends BaseEsMapper <Author > {
15+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .test .mapper ;
2+
3+
4+ import org .dromara .easyes .annotation .EsDS ;
5+ import org .dromara .easyes .core .core .BaseEsMapper ;
6+ import org .dromara .easyes .test .entity .Contact ;
7+
8+ /**
9+ * 父子类型-子文档的mapper
10+ * <p>
11+ * Copyright © 2024 xpc1024 All Rights Reserved
12+ **/
13+ @ EsDS ("ds1" )
14+ public interface ContactMapper extends BaseEsMapper <Contact > {
15+ }
Original file line number Diff line number Diff line change 1+ package org .dromara .easyes .test .settings ;
2+
3+ import org .dromara .easyes .annotation .rely .DefaultSettingsProvider ;
4+
5+ import java .util .HashMap ;
6+ import java .util .Map ;
7+
8+ /**
9+ * 由于es索引的settings灵活多变,框架只能针对一部分场景作简化,其余场景需要用户自定义实现
10+ * <p>
11+ * Copyright © 2024 xpc1024 All Rights Reserved
12+ **/
13+ public class MySettingsProvider extends DefaultSettingsProvider {
14+ @ Override
15+ public Map <String , Object > getSettings () {
16+ // TODO 这里可以自定义你的settings实现,将自定义的settings置入map并返回即可
17+ Map <String , Object > mySettings = new HashMap <>();
18+ // 例如指定查询操作的慢日志阈值为30秒,当查询操作的执行时间超过此阈值时,Elasticsearch会记录相应的慢日志并发出警告
19+ mySettings .put ("index.search.slowlog.threshold.query.warn" , "30s" );
20+ return mySettings ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments