# /
# ORM对象关系映射(easyes)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.dromara.easy-es/easy-es-boot-starter -->
<dependency>
<groupId>org.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version>2.0.0-beta4</version>
</dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
http://localhost:8080/insert
http://localhost:8080/listDocumentByTitle?title=测试1
[
{
"id": "1",
"title": "测试1",
"content": "测试内容1",
"creator": "老汉",
"gmtCreate": "2023-11-14 20:37:01",
"notExistsField": null,
"location": null,
"geoLocation": null,
"customField": null,
"highlightContent": null,
"starNum": null
}
]
http://localhost:8080/highlightSearch?content=测试
[
{
"id": "1",
"title": "测试1",
"content": "测试内容1",
"creator": "老汉",
"gmtCreate": "2023-11-14 20:37:01",
"notExistsField": null,
"location": null,
"geoLocation": null,
"customField": null,
"highlightContent": "<em>测</em><em>试</em>内容1",
"starNum": null
}
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
org.dromara.easyes.core.core.WrapperProcessor#initBool
private static void initBool(BoolQueryBuilder bool, Param param, EntityInfo entityInfo, Map<String, String> mappingColumnMap, Map<String, String> fieldTypeMap) {
try {
List<Param> children = param.getChildren();
BoolQueryBuilder queryBuilder;
RangeQueryBuilder rangeBuilder;
String realField;
AbstractQueryBuilder queryBuilder;
switch(param.getQueryTypeEnum()) {
case OR:
case NOT:
case FILTER:
break;
case MIX:
setBool(bool, param.getQueryBuilder(), param.getPrevQueryType());
break;
case TERM:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
queryBuilder = QueryBuilders.termQuery(realField, param.getVal()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case MATCH:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.matchQuery(realField, param.getVal()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case MATCH_PHRASE:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.matchPhraseQuery(realField, param.getVal()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case MATCH_PHRASE_PREFIX:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
QueryBuilder queryBuilder = ((MatchPhrasePrefixQueryBuilder)QueryBuilders.matchPhrasePrefixQuery(realField, param.getVal()).boost(param.getBoost())).maxExpansions((Integer)param.getExt1());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case MULTI_MATCH:
String[] realFields = FieldUtils.getRealFields(param.getColumns(), mappingColumnMap);
QueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(param.getVal(), realFields).operator((Operator)param.getExt1()).minimumShouldMatch(param.getExt2() + "%");
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case MATCH_ALL:
queryBuilder = QueryBuilders.matchAllQuery().boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case QUERY_STRING:
queryBuilder = QueryBuilders.queryStringQuery(param.getColumn()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case PREFIX:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.prefixQuery(realField, (String)param.getVal()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case GT:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
rangeBuilder = (RangeQueryBuilder)QueryBuilders.rangeQuery(realField).gt(param.getVal()).boost(param.getBoost());
Optional.ofNullable(param.getExt1()).ifPresent((ext1) -> {
rangeBuilder.timeZone(((ZoneId)ext1).getId());
});
Optional.ofNullable(param.getExt2()).ifPresent((ext2) -> {
rangeBuilder.format(ext2.toString());
});
setBool(bool, rangeBuilder, param.getPrevQueryType());
break;
case GE:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
rangeBuilder = (RangeQueryBuilder)QueryBuilders.rangeQuery(realField).gte(param.getVal()).boost(param.getBoost());
Optional.ofNullable(param.getExt1()).ifPresent((ext1) -> {
rangeBuilder.timeZone(((ZoneId)ext1).getId());
});
Optional.ofNullable(param.getExt2()).ifPresent((ext2) -> {
rangeBuilder.format(ext2.toString());
});
setBool(bool, rangeBuilder, param.getPrevQueryType());
break;
case LT:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
rangeBuilder = (RangeQueryBuilder)QueryBuilders.rangeQuery(realField).lt(param.getVal()).boost(param.getBoost());
Optional.ofNullable(param.getExt1()).ifPresent((ext1) -> {
rangeBuilder.timeZone(((ZoneId)ext1).getId());
});
Optional.ofNullable(param.getExt2()).ifPresent((ext2) -> {
rangeBuilder.format(ext2.toString());
});
setBool(bool, rangeBuilder, param.getPrevQueryType());
break;
case LE:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
rangeBuilder = (RangeQueryBuilder)QueryBuilders.rangeQuery(realField).lte(param.getVal()).boost(param.getBoost());
Optional.ofNullable(param.getExt1()).ifPresent((ext1) -> {
rangeBuilder.timeZone(((ZoneId)ext1).getId());
});
Optional.ofNullable(param.getExt2()).ifPresent((ext2) -> {
rangeBuilder.format(ext2.toString());
});
setBool(bool, rangeBuilder, param.getPrevQueryType());
break;
case BETWEEN:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
rangeBuilder = (RangeQueryBuilder)QueryBuilders.rangeQuery(realField).gte(param.getExt1()).lte(param.getExt2()).boost(param.getBoost());
Optional.ofNullable(param.getExt3()).ifPresent((ext3) -> {
rangeBuilder.timeZone(((ZoneId)ext3).getId());
});
Optional.ofNullable(param.getExt4()).ifPresent((ext4) -> {
rangeBuilder.format(ext4.toString());
});
setBool(bool, rangeBuilder, param.getPrevQueryType());
break;
case WILDCARD:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(realField, param.getVal().toString());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case TERMS:
realField = FieldUtils.getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap);
QueryBuilder queryBuilder = QueryBuilders.termsQuery(realField, (Collection)param.getVal());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case EXISTS:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.existsQuery(realField).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case GEO_BOUNDING_BOX:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.geoBoundingBoxQuery(realField).setCorners((GeoPoint)param.getExt1(), (GeoPoint)param.getExt2()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case GEO_DISTANCE:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
GeoDistanceQueryBuilder geoDistanceBuilder = (GeoDistanceQueryBuilder)QueryBuilders.geoDistanceQuery(realField).point((GeoPoint)param.getExt2()).boost(param.getBoost());
MyOptional.ofNullable(param.getExt1()).ifPresent((ext1) -> {
geoDistanceBuilder.distance((Double)param.getVal(), (DistanceUnit)ext1);
}, () -> {
return geoDistanceBuilder.distance((String)param.getVal());
});
setBool(bool, geoDistanceBuilder, param.getPrevQueryType());
break;
case GEO_POLYGON:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
QueryBuilder queryBuilder = QueryBuilders.geoPolygonQuery(realField, (List)param.getVal());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case GEO_SHAPE_ID:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.geoShapeQuery(realField, param.getVal().toString()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case GEO_SHAPE:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
queryBuilder = QueryBuilders.geoShapeQuery(realField, (Geometry)param.getVal()).relation((ShapeRelation)param.getExt1()).boost(param.getBoost());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case HAS_CHILD:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
QueryBuilder queryBuilder = new HasChildQueryBuilder(param.getExt1().toString(), QueryBuilders.matchQuery(param.getExt1().toString() + "." + realField, param.getVal()).boost(param.getBoost()), (ScoreMode)param.getExt2());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case HAS_PARENT:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
QueryBuilder queryBuilder = new HasParentQueryBuilder(param.getExt1().toString(), QueryBuilders.matchQuery(param.getExt1().toString() + "." + realField, param.getVal()).boost(param.getBoost()), (Boolean)param.getExt2());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case PARENT_ID:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
QueryBuilder queryBuilder = new ParentIdQueryBuilder(realField, param.getVal().toString());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case NESTED_AND:
case NESTED_FILTER:
case NESTED_NOT:
case NESTED_OR:
queryBuilder = getBool(children, QueryBuilders.boolQuery(), entityInfo, (String)null);
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
case NESTED:
realField = FieldUtils.getRealField(param.getColumn(), mappingColumnMap);
String[] split = param.getColumn().split("\\.");
queryBuilder = getBool(children, QueryBuilders.boolQuery(), entityInfo, split[split.length - 1]);
QueryBuilder queryBuilder = QueryBuilders.nestedQuery(realField, queryBuilder, (ScoreMode)param.getVal());
setBool(bool, queryBuilder, param.getPrevQueryType());
break;
default:
throw ExceptionUtils.eee("非法参数类型", new Object[0]);
}
} catch (Throwable var12) {
throw var12;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193