mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 09:39:04 +08:00
feat: jdk8 es-java7.17.28
This commit is contained in:
parent
79886798b2
commit
7d8e879b4b
@ -14,8 +14,8 @@
|
|||||||
<artifactId>easy-es-annotation</artifactId>
|
<artifactId>easy-es-annotation</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
<artifactId>easy-es-boot-starter</artifactId>
|
<artifactId>easy-es-boot-starter</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
<artifactId>easy-es-common</artifactId>
|
<artifactId>easy-es-common</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -49,18 +49,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version> <!-- 或者更高版本 -->
|
|
||||||
<configuration>
|
|
||||||
<source>21</source>
|
|
||||||
<target>21</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -30,8 +30,8 @@ public class BaseJoin {
|
|||||||
* @param parentId 父id
|
* @param parentId 父id
|
||||||
*/
|
*/
|
||||||
public void addJoinField(String fieldName, String name, String parentId) {
|
public void addJoinField(String fieldName, String name, String parentId) {
|
||||||
joinField = new HashMap<>() {{
|
joinField = new HashMap<String, Map<String, String>>() {{
|
||||||
put(fieldName, new HashMap<>() {{
|
put(fieldName, new HashMap<String, String>() {{
|
||||||
put("name", name);
|
put("name", name);
|
||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
put("parent", parentId);
|
put("parent", parentId);
|
||||||
|
|||||||
@ -22,7 +22,8 @@ public class JacksonCustomAnnotationIntrospector extends JacksonAnnotationIntros
|
|||||||
* 获取序列化和反序列化时的名称
|
* 获取序列化和反序列化时的名称
|
||||||
*/
|
*/
|
||||||
private static PropertyName getPropertyName(Annotated m) {
|
private static PropertyName getPropertyName(Annotated m) {
|
||||||
if (m instanceof AnnotatedField f) {
|
if (m instanceof AnnotatedField) {
|
||||||
|
AnnotatedField f = (AnnotatedField) m;
|
||||||
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
String jsonName = config.javaJsonFieldNameMap.get(f.getName());
|
String jsonName = config.javaJsonFieldNameMap.get(f.getName());
|
||||||
@ -58,7 +59,8 @@ public class JacksonCustomAnnotationIntrospector extends JacksonAnnotationIntros
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> c, Annotated a) {
|
public JsonIncludeProperties.Value findPropertyInclusionByName(MapperConfig<?> c, Annotated a) {
|
||||||
if (a instanceof AnnotatedClass f) {
|
if (a instanceof AnnotatedClass) {
|
||||||
|
AnnotatedClass f = (AnnotatedClass) a;
|
||||||
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getAnnotated());
|
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getAnnotated());
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
return config.allJsonField;
|
return config.allJsonField;
|
||||||
@ -73,7 +75,8 @@ public class JacksonCustomAnnotationIntrospector extends JacksonAnnotationIntros
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JsonFormat.Value findFormat(Annotated a) {
|
public JsonFormat.Value findFormat(Annotated a) {
|
||||||
if (a instanceof AnnotatedMethod f) {
|
if (a instanceof AnnotatedMethod) {
|
||||||
|
AnnotatedMethod f = (AnnotatedMethod) a;
|
||||||
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
JsonFormat.Value value = config.formatMap.get(f.getName());
|
JsonFormat.Value value = config.formatMap.get(f.getName());
|
||||||
@ -91,7 +94,8 @@ public class JacksonCustomAnnotationIntrospector extends JacksonAnnotationIntros
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JsonInclude.Value findPropertyInclusion(Annotated a) {
|
public JsonInclude.Value findPropertyInclusion(Annotated a) {
|
||||||
if (a instanceof AnnotatedMember f) {
|
if (a instanceof AnnotatedMember) {
|
||||||
|
AnnotatedMember f = (AnnotatedMember) a;
|
||||||
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
JacksonCustomConfig config = JacksonCustomConfig.jacksonConfigMap.get(f.getDeclaringClass());
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
JsonInclude.Value value = config.includeMap.get(f.getName());
|
JsonInclude.Value value = config.includeMap.get(f.getName());
|
||||||
|
|||||||
@ -14,8 +14,8 @@
|
|||||||
<artifactId>easy-es-core</artifactId>
|
<artifactId>easy-es-core</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import co.elastic.clients.elasticsearch.indices.PutMappingRequest;
|
|||||||
import co.elastic.clients.elasticsearch.indices.RefreshRequest;
|
import co.elastic.clients.elasticsearch.indices.RefreshRequest;
|
||||||
import co.elastic.clients.elasticsearch.indices.RefreshResponse;
|
import co.elastic.clients.elasticsearch.indices.RefreshResponse;
|
||||||
import co.elastic.clients.elasticsearch.sql.QueryResponse;
|
import co.elastic.clients.elasticsearch.sql.QueryResponse;
|
||||||
import co.elastic.clients.elasticsearch.sql.query.SqlFormat;
|
|
||||||
import co.elastic.clients.json.JsonData;
|
import co.elastic.clients.json.JsonData;
|
||||||
import co.elastic.clients.json.JsonpUtils;
|
import co.elastic.clients.json.JsonpUtils;
|
||||||
import co.elastic.clients.transport.TransportOptions;
|
import co.elastic.clients.transport.TransportOptions;
|
||||||
@ -166,7 +165,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public String executeSQL(String sql) {
|
public String executeSQL(String sql) {
|
||||||
PrintUtils.printSql(sql);
|
PrintUtils.printSql(sql);
|
||||||
QueryResponse response = client.sql().query(x -> x.query(sql).format(SqlFormat.Json));
|
QueryResponse response = client.sql().query(x -> x.query(sql).format("json"));
|
||||||
return JsonpUtils.toString(response, new StringBuilder()).toString();
|
return JsonpUtils.toString(response, new StringBuilder()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,8 +215,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
||||||
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
||||||
.routing(wrapper.routing)
|
.routing(wrapper.routing)
|
||||||
.preference(wrapper.preference)
|
.preference(wrapper.preference);
|
||||||
;
|
|
||||||
return builder.build().toString();
|
return builder.build().toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw ExceptionUtils.eee("get search source exception", e);
|
throw ExceptionUtils.eee("get search source exception", e);
|
||||||
@ -585,7 +583,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
if (CollectionUtils.isEmpty(searchHits)) {
|
if (CollectionUtils.isEmpty(searchHits)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return parseOne(searchHits.getFirst(), wrapper);
|
return parseOne(searchHits.get(0), wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -993,7 +991,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
SearchRequest searchRequest = new SearchRequest.Builder()
|
SearchRequest searchRequest = new SearchRequest.Builder()
|
||||||
.index(indexName)
|
.index(indexName)
|
||||||
.routing(routing)
|
.routing(routing)
|
||||||
.query(QueryBuilders.ids().values(List.of(id.toString())).build()._toQuery())
|
.query(QueryBuilders.ids().values(id.toString()).build()._toQuery())
|
||||||
.build();
|
.build();
|
||||||
// 请求es获取数据
|
// 请求es获取数据
|
||||||
List<Hit<T>> searchHits = getSearchHits(searchRequest);
|
List<Hit<T>> searchHits = getSearchHits(searchRequest);
|
||||||
@ -1002,7 +1000,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 解析数据并返回
|
// 解析数据并返回
|
||||||
return parseOne(searchHits.getFirst());
|
return parseOne(searchHits.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1036,8 +1034,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
||||||
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
||||||
.routing(wrapper.routing)
|
.routing(wrapper.routing)
|
||||||
.preference(wrapper.preference)
|
.preference(wrapper.preference);
|
||||||
;
|
|
||||||
|
|
||||||
if (needSearchAfter && CollectionUtils.isNotEmpty(searchAfter)) {
|
if (needSearchAfter && CollectionUtils.isNotEmpty(searchAfter)) {
|
||||||
builder.searchAfter(searchAfter);
|
builder.searchAfter(searchAfter);
|
||||||
@ -1271,7 +1268,8 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 嵌套对象为容器的情况
|
// 嵌套对象为容器的情况
|
||||||
if (invoke instanceof Collection<?> coll) {
|
if (invoke instanceof Collection<?>) {
|
||||||
|
Collection<?> coll = (Collection<?>) invoke;
|
||||||
Iterator<?> iterator = coll.iterator();
|
Iterator<?> iterator = coll.iterator();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@ -1414,9 +1412,10 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
|
|
||||||
// 针对父子类型-追加joinField信息
|
// 针对父子类型-追加joinField信息
|
||||||
if (StringUtils.isNotBlank(entityInfo.getJoinAlias())) {
|
if (StringUtils.isNotBlank(entityInfo.getJoinAlias())) {
|
||||||
if (!(entity instanceof BaseJoin b)) {
|
if (!(entity instanceof BaseJoin)) {
|
||||||
throw ExceptionUtils.eee("实体类" + entityClass.getName() + "必须继承BaseJoin实现Join功能");
|
throw ExceptionUtils.eee("实体类" + entityClass.getName() + "必须继承BaseJoin实现Join功能");
|
||||||
}
|
}
|
||||||
|
BaseJoin b = (BaseJoin) entity;
|
||||||
b.addJoinField(entityInfo.getJoinFieldName(), entityInfo.getJoinAlias(), entityInfo.isChild() ? parentId : null);
|
b.addJoinField(entityInfo.getJoinFieldName(), entityInfo.getJoinAlias(), entityInfo.isChild() ? parentId : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1619,7 +1618,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
if (Objects.nonNull(searchResponse)
|
if (Objects.nonNull(searchResponse)
|
||||||
&& searchResponse.shards().failures() != null
|
&& searchResponse.shards().failures() != null
|
||||||
&& searchResponse.shards().failures().size() > ZERO) {
|
&& searchResponse.shards().failures().size() > ZERO) {
|
||||||
String errorMsg = searchResponse.shards().failures().getFirst().toString();
|
String errorMsg = searchResponse.shards().failures().get(0).toString();
|
||||||
throw ExceptionUtils.eee("search response failed ,failedShards: " + errorMsg);
|
throw ExceptionUtils.eee("search response failed ,failedShards: " + errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1632,11 +1631,14 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
|||||||
private Refresh getRefreshPolicy() {
|
private Refresh getRefreshPolicy() {
|
||||||
// 防止傻狍子用户在全局中把刷新策略修改为GLOBAL
|
// 防止傻狍子用户在全局中把刷新策略修改为GLOBAL
|
||||||
final RefreshPolicy refreshPolicy = Optional.ofNullable(EntityInfoHelper.getEntityInfo(entityClass).getRefreshPolicy()).orElse(RefreshPolicy.NONE);
|
final RefreshPolicy refreshPolicy = Optional.ofNullable(EntityInfoHelper.getEntityInfo(entityClass).getRefreshPolicy()).orElse(RefreshPolicy.NONE);
|
||||||
return switch (refreshPolicy) {
|
switch (refreshPolicy) {
|
||||||
case RefreshPolicy.IMMEDIATE -> Refresh.True;
|
case IMMEDIATE:
|
||||||
case RefreshPolicy.WAIT_UNTIL -> Refresh.WaitFor;
|
return Refresh.True;
|
||||||
default -> Refresh.False;
|
case WAIT_UNTIL:
|
||||||
};
|
return Refresh.WaitFor;
|
||||||
|
default:
|
||||||
|
return Refresh.False;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -141,61 +141,57 @@ public class WrapperProcessor {
|
|||||||
break;
|
break;
|
||||||
case GT:
|
case GT:
|
||||||
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
||||||
query = Query.of(q -> q.range(p ->
|
query = Query.of(q -> q.range(p -> p
|
||||||
p.untyped(v -> {
|
.field(realField)
|
||||||
v.field(realField).gt(JsonData.of(param.getVal())).boost(param.getBoost());
|
.gt(JsonData.of(param.getVal()))
|
||||||
Optional.ofNullable(param.getExt1()).ifPresent(ext1 -> v.timeZone(((ZoneId) ext1).getId()));
|
.timeZone(param.getExt1() == null ? null : ((ZoneId) param.getExt1()).getId())
|
||||||
Optional.ofNullable(param.getExt2()).ifPresent(ext2 -> v.format(ext2.toString()));
|
.format((String)param.getExt2())
|
||||||
return v;
|
.boost(param.getBoost())
|
||||||
})
|
|
||||||
));
|
));
|
||||||
setBool(bool, query, param.getPrevQueryType());
|
setBool(bool, query, param.getPrevQueryType());
|
||||||
break;
|
break;
|
||||||
case GE:
|
case GE:
|
||||||
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
||||||
query = Query.of(q -> q.range(p ->
|
query = Query.of(q -> q.range(p -> p
|
||||||
p.untyped(v -> {
|
.field(realField)
|
||||||
v.field(realField).gte(JsonData.of(param.getVal())).boost(param.getBoost());
|
.gte(JsonData.of(param.getVal()))
|
||||||
Optional.ofNullable(param.getExt1()).ifPresent(ext1 -> v.timeZone(((ZoneId) ext1).getId()));
|
.timeZone(param.getExt1() == null ? null : ((ZoneId) param.getExt1()).getId())
|
||||||
Optional.ofNullable(param.getExt2()).ifPresent(ext2 -> v.format(ext2.toString()));
|
.format((String)param.getExt2())
|
||||||
return v;
|
.boost(param.getBoost())
|
||||||
})
|
|
||||||
));
|
));
|
||||||
setBool(bool, query, param.getPrevQueryType());
|
setBool(bool, query, param.getPrevQueryType());
|
||||||
break;
|
break;
|
||||||
case LT:
|
case LT:
|
||||||
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
||||||
query = Query.of(q -> q.range(p ->
|
query = Query.of(q -> q.range(p -> p
|
||||||
p.untyped(v -> {
|
.field(realField)
|
||||||
v.field(realField).lt(JsonData.of(param.getVal())).boost(param.getBoost());
|
.lt(JsonData.of(param.getVal()))
|
||||||
Optional.ofNullable(param.getExt1()).ifPresent(ext1 -> v.timeZone(((ZoneId) ext1).getId()));
|
.timeZone(param.getExt1() == null ? null : ((ZoneId) param.getExt1()).getId())
|
||||||
Optional.ofNullable(param.getExt2()).ifPresent(ext2 -> v.format(ext2.toString()));
|
.format((String)param.getExt2())
|
||||||
return v;
|
.boost(param.getBoost())
|
||||||
})
|
|
||||||
));
|
));
|
||||||
setBool(bool, query, param.getPrevQueryType());
|
setBool(bool, query, param.getPrevQueryType());
|
||||||
break;
|
break;
|
||||||
case LE:
|
case LE:
|
||||||
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
||||||
query = Query.of(q -> q.range(p ->
|
query = Query.of(q -> q.range(p -> p
|
||||||
p.untyped(v -> {
|
.field(realField)
|
||||||
v.field(realField).lte(JsonData.of(param.getVal())).boost(param.getBoost());
|
.lte(JsonData.of(param.getVal()))
|
||||||
Optional.ofNullable(param.getExt1()).ifPresent(ext1 -> v.timeZone(((ZoneId) ext1).getId()));
|
.timeZone(param.getExt1() == null ? null : ((ZoneId) param.getExt1()).getId())
|
||||||
Optional.ofNullable(param.getExt2()).ifPresent(ext2 -> v.format(ext2.toString()));
|
.format((String)param.getExt2())
|
||||||
return v;
|
.boost(param.getBoost())
|
||||||
})
|
|
||||||
));
|
));
|
||||||
setBool(bool, query, param.getPrevQueryType());
|
setBool(bool, query, param.getPrevQueryType());
|
||||||
break;
|
break;
|
||||||
case BETWEEN:
|
case BETWEEN:
|
||||||
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
realField = getRealFieldAndSuffix(param.getColumn(), fieldTypeMap, mappingColumnMap, entityInfo);
|
||||||
query = Query.of(q -> q.range(p ->
|
query = Query.of(q -> q.range(p -> p
|
||||||
p.untyped(v -> {
|
.field(realField)
|
||||||
v.field(realField).gte(JsonData.of(param.getExt1())).lte(JsonData.of(param.getExt2())).boost(param.getBoost());
|
.gte(JsonData.of(param.getExt1()))
|
||||||
Optional.ofNullable(param.getExt3()).ifPresent(ex -> v.timeZone(((ZoneId) ex).getId()));
|
.lte(JsonData.of(param.getExt2()))
|
||||||
Optional.ofNullable(param.getExt4()).ifPresent(ex -> v.format(ex.toString()));
|
.timeZone(param.getExt3() == null ? null : ((ZoneId) param.getExt3()).getId())
|
||||||
return v;
|
.format((String)param.getExt4())
|
||||||
})
|
.boost(param.getBoost())
|
||||||
));
|
));
|
||||||
setBool(bool, query, param.getPrevQueryType());
|
setBool(bool, query, param.getPrevQueryType());
|
||||||
break;
|
break;
|
||||||
@ -330,17 +326,24 @@ public class WrapperProcessor {
|
|||||||
* @return FieldValue
|
* @return FieldValue
|
||||||
*/
|
*/
|
||||||
public static FieldValue fieldValue(Object val) {
|
public static FieldValue fieldValue(Object val) {
|
||||||
return switch (val) {
|
if (val == null) {
|
||||||
case null -> FieldValue.NULL;
|
return FieldValue.NULL;
|
||||||
case FieldValue fieldValue -> fieldValue;
|
}
|
||||||
case Long l -> FieldValue.of((long) val);
|
|
||||||
case Integer i -> FieldValue.of((int) val);
|
|
||||||
case Double v -> FieldValue.of((double) val);
|
|
||||||
case Boolean b -> FieldValue.of((boolean) val);
|
|
||||||
case String s -> FieldValue.of(s);
|
|
||||||
default -> FieldValue.of(val);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (val instanceof FieldValue) {
|
||||||
|
return (FieldValue) val;
|
||||||
|
} else if (val instanceof Long) {
|
||||||
|
return FieldValue.of((long) val);
|
||||||
|
} else if (val instanceof Integer) {
|
||||||
|
return FieldValue.of((int) val);
|
||||||
|
} else if (val instanceof Double) {
|
||||||
|
return FieldValue.of((double) val);
|
||||||
|
} else if (val instanceof Boolean) {
|
||||||
|
return FieldValue.of((boolean) val);
|
||||||
|
} else if (val instanceof String) {
|
||||||
|
return FieldValue.of((String) val);
|
||||||
|
}
|
||||||
|
return FieldValue.of(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -584,7 +587,7 @@ public class WrapperProcessor {
|
|||||||
HighlightField field = HighlightField.of(x -> x
|
HighlightField field = HighlightField.of(x -> x
|
||||||
.preTags(highLightParam.getPreTag())
|
.preTags(highLightParam.getPreTag())
|
||||||
.postTags(highLightParam.getPostTag())
|
.postTags(highLightParam.getPostTag())
|
||||||
.type(highLightParam.getHighLightType().getValue())
|
.type(a -> a.custom(highLightParam.getHighLightType().getValue()))
|
||||||
.requireFieldMatch(highLightParam.getRequireFieldMatch())
|
.requireFieldMatch(highLightParam.getRequireFieldMatch())
|
||||||
);
|
);
|
||||||
highlightBuilder.fields(highlightField, field);
|
highlightBuilder.fields(highlightField, field);
|
||||||
@ -643,18 +646,24 @@ public class WrapperProcessor {
|
|||||||
* @return 排序器
|
* @return 排序器
|
||||||
*/
|
*/
|
||||||
private static SortOptions getSortBuilder(String realField, BaseSortParam baseSortParam) {
|
private static SortOptions getSortBuilder(String realField, BaseSortParam baseSortParam) {
|
||||||
return switch (baseSortParam.getOrderTypeEnum()) {
|
switch (baseSortParam.getOrderTypeEnum()) {
|
||||||
case FIELD -> SortOptions.of(x -> x.field(y -> y.field(realField).order(baseSortParam.getSortOrder())));
|
case FIELD:
|
||||||
case SCORE -> SortOptions.of(x -> x.score(y -> y.order(baseSortParam.getSortOrder())));
|
return SortOptions.of(x -> x.field(y -> y.field(realField).order(baseSortParam.getSortOrder())));
|
||||||
case GEO -> SortOptions.of(x -> x.geoDistance(y -> y
|
case SCORE:
|
||||||
.field(realField)
|
return SortOptions.of(x -> x.score(y -> y.order(baseSortParam.getSortOrder())));
|
||||||
.location(baseSortParam.getGeoPoints())
|
case GEO:
|
||||||
.order(baseSortParam.getSortOrder())
|
return SortOptions.of(x -> x.geoDistance(y -> y
|
||||||
.distanceType(baseSortParam.getGeoDistanceType())
|
.field(realField)
|
||||||
.unit(baseSortParam.getUnit())
|
.location(baseSortParam.getGeoPoints())
|
||||||
));
|
.order(baseSortParam.getSortOrder())
|
||||||
case CUSTOMIZE -> baseSortParam.getSortBuilder();
|
.distanceType(baseSortParam.getGeoDistanceType())
|
||||||
};
|
.unit(baseSortParam.getUnit())
|
||||||
|
));
|
||||||
|
case CUSTOMIZE:
|
||||||
|
return baseSortParam.getSortBuilder();
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -739,17 +748,24 @@ public class WrapperProcessor {
|
|||||||
List<NamedValue<SortOrder>> bucketOrders
|
List<NamedValue<SortOrder>> bucketOrders
|
||||||
) {
|
) {
|
||||||
// 解决同一个字段聚合多次,如min(starNum), max(starNum) 字段名重复问题
|
// 解决同一个字段聚合多次,如min(starNum), max(starNum) 字段名重复问题
|
||||||
return switch (aggType) {
|
switch (aggType) {
|
||||||
case AVG -> new Aggregation.Builder().avg(x -> x.field(realField));
|
case AVG:
|
||||||
case MIN -> new Aggregation.Builder().min(x -> x.field(realField));
|
return new Aggregation.Builder().avg(x -> x.field(realField));
|
||||||
case MAX -> new Aggregation.Builder().max(x -> x.field(realField));
|
case MIN:
|
||||||
case SUM -> new Aggregation.Builder().sum(x -> x.field(realField));
|
return new Aggregation.Builder().min(x -> x.field(realField));
|
||||||
case TERMS -> new Aggregation.Builder().terms(x -> {
|
case MAX:
|
||||||
x.field(realField);
|
return new Aggregation.Builder().max(x -> x.field(realField));
|
||||||
Optional.ofNullable(size).ifPresent(x::size);
|
case SUM:
|
||||||
Optional.ofNullable(bucketOrders).ifPresent(x::order);
|
return new Aggregation.Builder().sum(x -> x.field(realField));
|
||||||
return x;
|
case TERMS:
|
||||||
});
|
return new Aggregation.Builder().terms(x -> {
|
||||||
};
|
x.field(realField);
|
||||||
|
Optional.ofNullable(size).ifPresent(x::size);
|
||||||
|
Optional.ofNullable(bucketOrders).ifPresent(x::order);
|
||||||
|
return x;
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,12 +85,16 @@ public class GeoUtils {
|
|||||||
return createFromGeoHash(geohash);
|
return createFromGeoHash(geohash);
|
||||||
} else {
|
} else {
|
||||||
Rectangle rectangle = Geohash.toBoundingBox(geohash);
|
Rectangle rectangle = Geohash.toBoundingBox(geohash);
|
||||||
return switch (effectivePoint) {
|
switch (effectivePoint) {
|
||||||
case TOP_LEFT -> create(rectangle.getMaxY(), rectangle.getMinX());
|
case TOP_LEFT:
|
||||||
case TOP_RIGHT -> create(rectangle.getMaxY(), rectangle.getMaxX());
|
return create(rectangle.getMaxY(), rectangle.getMinX());
|
||||||
case BOTTOM_RIGHT -> create(rectangle.getMinY(), rectangle.getMaxX());
|
case TOP_RIGHT:
|
||||||
default -> throw new IllegalArgumentException("Unsupported effective point " + effectivePoint);
|
return create(rectangle.getMaxY(), rectangle.getMaxX());
|
||||||
};
|
case BOTTOM_RIGHT:
|
||||||
|
return create(rectangle.getMinY(), rectangle.getMaxX());
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unsupported effective point " + effectivePoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,8 +132,14 @@ public class GeoUtils {
|
|||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> toMap(Geometry geometry) {
|
public static Map<String, Object> toMap(Geometry geometry) {
|
||||||
|
String geoJsonName = null;
|
||||||
|
try {
|
||||||
|
geoJsonName = getGeoJsonName(geometry);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
Map<String, Object> root = new HashMap<>();
|
Map<String, Object> root = new HashMap<>();
|
||||||
root.put("type", getGeoJsonName(geometry));
|
root.put("type", geoJsonName);
|
||||||
|
|
||||||
geometry.visit(new GeometryVisitor<Void, RuntimeException>() {
|
geometry.visit(new GeometryVisitor<Void, RuntimeException>() {
|
||||||
@Override
|
@Override
|
||||||
@ -267,8 +277,8 @@ public class GeoUtils {
|
|||||||
* @param geometry geometry
|
* @param geometry geometry
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public static String getGeoJsonName(Geometry geometry) {
|
public static String getGeoJsonName(Geometry geometry) throws Exception {
|
||||||
return geometry.visit(new GeometryVisitor<>() {
|
return geometry.visit(new GeometryVisitor<String, Exception>() {
|
||||||
@Override
|
@Override
|
||||||
public String visit(Circle circle) {
|
public String visit(Circle circle) {
|
||||||
return "Circle";
|
return "Circle";
|
||||||
|
|||||||
@ -134,9 +134,10 @@ public class PrintUtils {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(body instanceof NdJsonpSerializable nd)) {
|
if (!(body instanceof NdJsonpSerializable)) {
|
||||||
return JsonpUtils.toJsonString(body, mapper);
|
return JsonpUtils.toJsonString(body, mapper);
|
||||||
}
|
}
|
||||||
|
NdJsonpSerializable nd = (NdJsonpSerializable) body;
|
||||||
|
|
||||||
StringBuilder bodyStr = new StringBuilder();
|
StringBuilder bodyStr = new StringBuilder();
|
||||||
collectNdJsonLines(bodyStr, nd, mapper);
|
collectNdJsonLines(bodyStr, nd, mapper);
|
||||||
@ -156,7 +157,8 @@ public class PrintUtils {
|
|||||||
Object item = values.next();
|
Object item = values.next();
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
// skip
|
// skip
|
||||||
} else if (item instanceof NdJsonpSerializable nd && item != value) { // do not recurse on the item itself
|
} else if (item instanceof NdJsonpSerializable && item != value) {
|
||||||
|
NdJsonpSerializable nd = (NdJsonpSerializable) item; // do not recurse on the item itself
|
||||||
collectNdJsonLines(body, nd, mapper);
|
collectNdJsonLines(body, nd, mapper);
|
||||||
} else {
|
} else {
|
||||||
body.append(JsonpUtils.toJsonString(item, mapper)).append("\n");
|
body.append(JsonpUtils.toJsonString(item, mapper)).append("\n");
|
||||||
|
|||||||
@ -14,8 +14,8 @@
|
|||||||
<artifactId>easy-es-extension</artifactId>
|
<artifactId>easy-es-extension</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -32,9 +32,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<lombok.version>1.18.36</lombok.version>
|
<lombok.version>1.18.36</lombok.version>
|
||||||
<elasticsearch.java.version>8.17.1</elasticsearch.java.version>
|
<elasticsearch.java.version>7.17.28</elasticsearch.java.version>
|
||||||
<jackson.version>2.18.2</jackson.version>
|
<jackson.version>2.18.2</jackson.version>
|
||||||
<fastjson.version>1.2.83</fastjson.version>
|
|
||||||
<jakarta.json.version>2.1.3</jakarta.json.version>
|
<jakarta.json.version>2.1.3</jakarta.json.version>
|
||||||
<codec.version>1.13</codec.version>
|
<codec.version>1.13</codec.version>
|
||||||
<spring-boot.version>2.7.16</spring-boot.version>
|
<spring-boot.version>2.7.16</spring-boot.version>
|
||||||
@ -99,12 +98,6 @@
|
|||||||
<version>${elasticsearch.java.version}</version>
|
<version>${elasticsearch.java.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>fastjson</artifactId>
|
|
||||||
<version>${fastjson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.json</groupId>
|
<groupId>jakarta.json</groupId>
|
||||||
<artifactId>jakarta.json-api</artifactId>
|
<artifactId>jakarta.json-api</artifactId>
|
||||||
|
|||||||
@ -10,8 +10,8 @@
|
|||||||
<artifactId>easy-es-solon-plugin</artifactId>
|
<artifactId>easy-es-solon-plugin</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
<artifactId>easy-es-solon-test</artifactId>
|
<artifactId>easy-es-solon-test</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -11,8 +11,8 @@
|
|||||||
<artifactId>easy-es-spring-test</artifactId>
|
<artifactId>easy-es-spring-test</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<junit-jupiter-engine.version>5.8.2</junit-jupiter-engine.version>
|
<junit-jupiter-engine.version>5.8.2</junit-jupiter-engine.version>
|
||||||
<spring-boot.version>2.7.18</spring-boot.version>
|
<spring-boot.version>2.7.18</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
<artifactId>easy-es-spring</artifactId>
|
<artifactId>easy-es-spring</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
<artifactId>easy-es-springboot-test</artifactId>
|
<artifactId>easy-es-springboot-test</artifactId>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user