mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
feat: 优化索引创建
This commit is contained in:
parent
2d8692fdc3
commit
aaced54f5d
@ -1,6 +1,7 @@
|
||||
package org.dromara.easyes.common.join;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -9,11 +10,12 @@ import java.util.Map;
|
||||
@Setter
|
||||
public class BaseJoin {
|
||||
|
||||
public Map<String, Map<String, String>> joinFiled;
|
||||
@JsonIgnore
|
||||
public Map<String, Map<String, String>> joinField;
|
||||
|
||||
@JsonAnyGetter
|
||||
public Map<String, Map<String, String>> getJoinField() {
|
||||
return joinFiled;
|
||||
return joinField;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,7 +30,7 @@ public class BaseJoin {
|
||||
* @param parentId 父id
|
||||
*/
|
||||
public void addJoinField(String fieldName, String name, String parentId) {
|
||||
joinFiled = new HashMap<>() {{
|
||||
joinField = new HashMap<>() {{
|
||||
put(fieldName, new HashMap<>() {{
|
||||
put("name", name);
|
||||
if (parentId != null) {
|
||||
|
||||
@ -35,6 +35,7 @@ public class JsonUtils {
|
||||
// 反序列化时是否将一个对象封装成单元素数组
|
||||
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
|
||||
.configure(SerializationFeature.INDENT_OUTPUT, false)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.build();
|
||||
AnnotationIntrospector anno = base.getSerializerProviderInstance().getAnnotationIntrospector();
|
||||
base.setAnnotationIntrospector(new AnnotationIntrospectorPair(anno, new JacksonCustomAnnotationIntrospector()));
|
||||
|
||||
@ -1666,21 +1666,21 @@ public interface Func<Children, R> extends Serializable {
|
||||
/**
|
||||
* 用户自定义SearchRequest.Builder 用于混合查询
|
||||
*
|
||||
* @param searchSourceBuilder 用户自定义的SearchSourceBuilder
|
||||
* @param searchBuilder 用户自定义的SearchSourceBuilder
|
||||
* @return wrapper
|
||||
*/
|
||||
default Children setSearchSourceBuilder(SearchRequest.Builder searchSourceBuilder) {
|
||||
return setSearchSourceBuilder(true, searchSourceBuilder);
|
||||
default Children setSearchBuilder(SearchRequest.Builder searchBuilder) {
|
||||
return setSearchBuilder(true, searchBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自定义SearchRequest.Builder 用于混合查询
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param searchSourceBuilder 用户自定义的SearchSourceBuilder
|
||||
* @param condition 执行条件
|
||||
* @param searchBuilder 用户自定义的SearchSourceBuilder
|
||||
* @return wrapper
|
||||
*/
|
||||
Children setSearchSourceBuilder(boolean condition, SearchRequest.Builder searchSourceBuilder);
|
||||
Children setSearchBuilder(boolean condition, SearchRequest.Builder searchBuilder);
|
||||
|
||||
/**
|
||||
* 混合查询
|
||||
|
||||
@ -657,8 +657,8 @@ public abstract class AbstractChainWrapper<T, R, Children extends AbstractChainW
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children setSearchSourceBuilder(boolean condition, SearchRequest.Builder searchSourceBuilder) {
|
||||
getWrapper().setSearchSourceBuilder(condition, searchSourceBuilder);
|
||||
public Children setSearchBuilder(boolean condition, SearchRequest.Builder searchSourceBuilder) {
|
||||
getWrapper().setSearchBuilder(condition, searchSourceBuilder);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
|
||||
@ -593,9 +593,9 @@ public abstract class AbstractWrapper<T, R, Children extends AbstractWrapper<T,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Children setSearchSourceBuilder(boolean condition, SearchRequest.Builder searchSourceBuilder) {
|
||||
public Children setSearchBuilder(boolean condition, SearchRequest.Builder searchBuilder) {
|
||||
if (condition) {
|
||||
this.searchBuilder = searchSourceBuilder;
|
||||
this.searchBuilder = searchBuilder;
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -499,6 +499,16 @@ public interface BaseEsMapper<T> {
|
||||
*/
|
||||
Integer updateBatchByIds(String routing, Collection<T> entityList, String... indexNames);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param updateWrapper 条件
|
||||
* @return 成功条数
|
||||
*/
|
||||
default Integer update(Wrapper<T> updateWrapper) {
|
||||
return update(null, updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
|
||||
@ -23,13 +23,12 @@ import co.elastic.clients.elasticsearch.indices.RefreshResponse;
|
||||
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.JsonpUtils;
|
||||
import co.elastic.clients.transport.TransportOptions;
|
||||
import co.elastic.clients.transport.rest_client.RestClientTransport;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.dromara.easyes.annotation.rely.IdType;
|
||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
||||
@ -69,17 +68,15 @@ import static org.dromara.easyes.core.kernel.WrapperProcessor.getIndexName;
|
||||
* </p>
|
||||
* Copyright © 2021 xpc1024 All Rights Reserved
|
||||
**/
|
||||
@Setter
|
||||
public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
private static final Log log = LogFactory.getLog(BaseEsMapperImpl.class);
|
||||
/**
|
||||
* restHighLevel client
|
||||
*/
|
||||
@Setter
|
||||
private ElasticsearchClient client;
|
||||
/**
|
||||
* T 对应的类
|
||||
*/
|
||||
@Setter
|
||||
private Class<T> entityClass;
|
||||
|
||||
@Override
|
||||
@ -169,7 +166,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
@SneakyThrows
|
||||
public String executeSQL(String sql) {
|
||||
QueryResponse response = client.sql().query(x -> x.query(sql).format(SqlFormat.Json));
|
||||
return response.toString();
|
||||
return JsonpUtils.toString(response, new StringBuilder()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,7 +202,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
|
||||
@Override
|
||||
public SearchRequest.Builder getSearchSourceBuilder(Wrapper<T> wrapper) {
|
||||
return WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass);
|
||||
return WrapperProcessor.buildSearchBuilder(wrapper, entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -213,7 +210,11 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
try {
|
||||
// 用户在wrapper中指定的混合查询条件优先级最高
|
||||
SearchRequest.Builder builder = Optional.ofNullable(wrapper.searchBuilder)
|
||||
.orElse(WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass));
|
||||
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
||||
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
||||
.routing(wrapper.routing)
|
||||
.preference(wrapper.preference)
|
||||
;
|
||||
return builder.build().toString();
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.eee("get search source exception", e);
|
||||
@ -751,8 +752,6 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
);
|
||||
|
||||
// 执行批量请求并返回结果
|
||||
PrintUtils.printDsl(bulkRequest, client);
|
||||
|
||||
return doBulkRequest(bulkRequest, Result.Created.jsonValue());
|
||||
}
|
||||
|
||||
@ -844,7 +843,6 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
.operations(operations)
|
||||
);
|
||||
|
||||
PrintUtils.printDsl(request, client);
|
||||
return doBulkRequest(request, Result.Deleted.jsonValue());
|
||||
}
|
||||
|
||||
@ -950,7 +948,6 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
.operations(operations)
|
||||
);
|
||||
|
||||
PrintUtils.printDsl(request, client);
|
||||
return doBulkRequest(request, Result.Updated.jsonValue());
|
||||
}
|
||||
|
||||
@ -1037,7 +1034,11 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
private SearchResponse<T> getSearchResponse(Wrapper<T> wrapper, List<FieldValue> searchAfter, boolean needSearchAfter) {
|
||||
// 用户在wrapper中指定的混合查询条件优先级最高
|
||||
SearchRequest.Builder builder = Optional.ofNullable(wrapper.searchBuilder)
|
||||
.orElse(WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass));
|
||||
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
||||
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
||||
.routing(wrapper.routing)
|
||||
.preference(wrapper.preference)
|
||||
;
|
||||
|
||||
if (needSearchAfter && CollectionUtils.isNotEmpty(searchAfter)) {
|
||||
builder.searchAfter(searchAfter);
|
||||
@ -1466,6 +1467,7 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
* @return 成功个数
|
||||
*/
|
||||
private Integer doBulkRequest(BulkRequest bulkRequest, String successResult) {
|
||||
PrintUtils.printDsl(bulkRequest, client);
|
||||
try {
|
||||
BulkResponse bulkResponse = client.withTransportOptions(getTransportOptions()).bulk(bulkRequest);
|
||||
if (bulkResponse.errors()) {
|
||||
@ -1490,7 +1492,11 @@ public class BaseEsMapperImpl<T> implements BaseEsMapper<T> {
|
||||
private List<Hit<T>> getSearchHits(Wrapper<T> wrapper) {
|
||||
// 用户在wrapper中指定的混合查询条件优先级最高
|
||||
SearchRequest searchRequest = Optional.ofNullable(wrapper.searchBuilder)
|
||||
.orElse(WrapperProcessor.buildSearchSourceBuilder(wrapper, entityClass)).build();
|
||||
.orElse(WrapperProcessor.buildSearchBuilder(wrapper, entityClass))
|
||||
.index(WrapperProcessor.getIndexName(entityClass, wrapper.indexNames))
|
||||
.routing(wrapper.routing)
|
||||
.preference(wrapper.preference)
|
||||
.build();
|
||||
|
||||
PrintUtils.printDsl(searchRequest, client);
|
||||
SearchResponse<T> response;
|
||||
|
||||
@ -17,6 +17,7 @@ import org.dromara.easyes.core.biz.*;
|
||||
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
||||
import org.dromara.easyes.core.toolkit.FieldUtils;
|
||||
import org.dromara.easyes.core.toolkit.GeoUtils;
|
||||
import org.dromara.easyes.core.toolkit.TreeBuilder;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
|
||||
@ -43,12 +44,12 @@ public class WrapperProcessor {
|
||||
* @param entityClass 实体类
|
||||
* @return ES查询参数
|
||||
*/
|
||||
public static SearchRequest.Builder buildSearchSourceBuilder(Wrapper<?> wrapper, Class<?> entityClass) {
|
||||
public static SearchRequest.Builder buildSearchBuilder(Wrapper<?> wrapper, Class<?> entityClass) {
|
||||
// 初始化boolQueryBuilder 参数
|
||||
BoolQuery.Builder boolQueryBuilder = initBoolQueryBuilder(wrapper.paramQueue, entityClass);
|
||||
|
||||
// 初始化searchSourceBuilder 参数
|
||||
SearchRequest.Builder searchSourceBuilder = initSearchSourceBuilder(wrapper, entityClass);
|
||||
SearchRequest.Builder searchSourceBuilder = initSearchBuilder(wrapper, entityClass);
|
||||
|
||||
// 设置boolQuery参数
|
||||
searchSourceBuilder.query(x -> x.bool(boolQueryBuilder.build()));
|
||||
@ -191,8 +192,8 @@ public class WrapperProcessor {
|
||||
query = Query.of(q -> q.range(p ->
|
||||
p.untyped(v -> {
|
||||
v.field(realField).gte(JsonData.of(param.getExt1())).lte(JsonData.of(param.getExt2())).boost(param.getBoost());
|
||||
Optional.ofNullable(param.getExt1()).ifPresent(ext1 -> v.timeZone(((ZoneId) ext1).getId()));
|
||||
Optional.ofNullable(param.getExt2()).ifPresent(ext2 -> v.format(ext2.toString()));
|
||||
Optional.ofNullable(param.getExt3()).ifPresent(ex -> v.timeZone(((ZoneId) ex).getId()));
|
||||
Optional.ofNullable(param.getExt4()).ifPresent(ex -> v.format(ex.toString()));
|
||||
return v;
|
||||
})
|
||||
));
|
||||
@ -228,11 +229,10 @@ public class WrapperProcessor {
|
||||
case GEO_DISTANCE:
|
||||
realField = getRealField(param.getColumn(), mappingColumnMap);
|
||||
query = Query.of(q -> q.geoDistance(p -> {
|
||||
p.field(realField).location(x -> x.latlon((LatLonGeoLocation) param.getExt2())).boost(param.getBoost());
|
||||
p.field(realField).location((GeoLocation) param.getExt2()).boost(param.getBoost());
|
||||
String unit = param.getExt1() == null ? DistanceUnit.Meters.jsonValue() : ((DistanceUnit) param.getExt1()).jsonValue();
|
||||
String val = (String) param.getVal();
|
||||
String distance = val.endsWith(unit) ? val : val + unit;
|
||||
p.distance(distance);
|
||||
Double distance = (Double) param.getVal();
|
||||
p.distance(distance + unit);
|
||||
return p;
|
||||
}));
|
||||
setBool(bool, query, param.getPrevQueryType());
|
||||
@ -240,7 +240,7 @@ public class WrapperProcessor {
|
||||
case GEO_POLYGON:
|
||||
realField = getRealField(param.getColumn(), mappingColumnMap);
|
||||
query = Query.of(q -> q.geoPolygon(p -> p.field(realField).polygon(x ->
|
||||
x.points((List<GeoLocation>) param.getExt2()))));
|
||||
x.points((List<GeoLocation>) param.getVal()))));
|
||||
setBool(bool, query, param.getPrevQueryType());
|
||||
break;
|
||||
case GEO_SHAPE_ID:
|
||||
@ -251,10 +251,15 @@ public class WrapperProcessor {
|
||||
break;
|
||||
case GEO_SHAPE:
|
||||
realField = getRealField(param.getColumn(), mappingColumnMap);
|
||||
query = Query.of(q -> q.geoShape(p -> p.field(realField).shape(x ->
|
||||
x.shape(JsonData.of((Geometry)param.getVal())).relation((GeoShapeRelation) param.getExt1())
|
||||
).boost(param.getBoost())
|
||||
));
|
||||
query = QueryBuilders.geoShape()
|
||||
.field(realField)
|
||||
.shape(x -> x
|
||||
// .shape(JsonData.of(WellKnownText.toWKT(val)))
|
||||
.shape(JsonData.of(GeoUtils.toMap((Geometry) param.getVal())))
|
||||
.relation((GeoShapeRelation) param.getExt1())
|
||||
)
|
||||
.boost(param.getBoost())
|
||||
.build()._toQuery();
|
||||
setBool(bool, query, param.getPrevQueryType());
|
||||
break;
|
||||
case PARENT_ID:
|
||||
@ -417,17 +422,13 @@ public class WrapperProcessor {
|
||||
* @param wrapper 条件
|
||||
* @return SearchSourceBuilder
|
||||
*/
|
||||
private static SearchRequest.Builder initSearchSourceBuilder(Wrapper<?> wrapper, Class<?> entityClass) {
|
||||
private static SearchRequest.Builder initSearchBuilder(Wrapper<?> wrapper, Class<?> entityClass) {
|
||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||
// 获取自定义字段map
|
||||
Map<String, String> mappingColumnMap = entityInfo.getMappingColumnMap();
|
||||
|
||||
SearchRequest.Builder builder = new SearchRequest.Builder();
|
||||
|
||||
builder.index(getIndexName(entityClass, wrapper.indexNames));
|
||||
builder.routing(wrapper.routing);
|
||||
builder.preference(wrapper.preference);
|
||||
|
||||
// 设置高亮
|
||||
setHighLight(entityInfo.getHighlightParams(), builder);
|
||||
|
||||
@ -666,17 +667,19 @@ public class WrapperProcessor {
|
||||
Aggregation.Builder.ContainerBuilder cursor = null;
|
||||
for (AggregationParam aggParam : aggregationParamList) {
|
||||
String realField = getRealField(aggParam.getField(), mappingColumnMap);
|
||||
Aggregation.Builder.ContainerBuilder builder = getRealAggregationBuilder(aggParam.getAggregationType()
|
||||
, aggParam.getName(), realField, wrapper.size, wrapper.bucketOrders);
|
||||
Aggregation.Builder.ContainerBuilder builder = getRealAggregationBuilder(
|
||||
aggParam.getAggregationType(), realField, wrapper.size, wrapper.bucketOrders);
|
||||
// 解决同一个字段聚合多次,如min(starNum), max(starNum) 字段名重复问题
|
||||
String aggName = aggParam.getName() + aggParam.getAggregationType().getValue();
|
||||
if (aggParam.isEnablePipeline()) {
|
||||
// 管道聚合, 构造聚合树
|
||||
if (root == null) {
|
||||
root = builder;
|
||||
rootName = aggParam.getName();
|
||||
rootName = aggName;
|
||||
cursor = root;
|
||||
} else {
|
||||
Aggregation agg = builder.build();
|
||||
cursor.aggregations(aggParam.getName(), agg);
|
||||
cursor.aggregations(aggName, agg);
|
||||
// 解决max、min、avg和sum聚合函数不支持sub-aggregations的问题
|
||||
if (agg._kind().equals(Aggregation.Kind.Terms)) {
|
||||
cursor = builder;
|
||||
@ -685,7 +688,7 @@ public class WrapperProcessor {
|
||||
} else {
|
||||
// 非管道聚合
|
||||
if (builder != null) {
|
||||
searchSourceBuilder.aggregations(aggParam.getName(), builder.build());
|
||||
searchSourceBuilder.aggregations(aggName, builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -704,38 +707,28 @@ public class WrapperProcessor {
|
||||
* 根据聚合类型获取具体的聚合建造者
|
||||
*
|
||||
* @param aggType 聚合类型
|
||||
* @param name 聚合返回桶的名称 保持原字段名称
|
||||
* @param realField 原字段名称
|
||||
* @param size 聚合桶大小
|
||||
* @return 聚合建造者
|
||||
*/
|
||||
private static Aggregation.Builder.ContainerBuilder getRealAggregationBuilder(
|
||||
AggregationTypeEnum aggType,
|
||||
String name,
|
||||
String realField,
|
||||
Integer size,
|
||||
List<NamedValue<SortOrder>> bucketOrders
|
||||
) {
|
||||
// 解决同一个字段聚合多次,如min(starNum), max(starNum) 字段名重复问题
|
||||
String finalName = name + aggType.getValue();
|
||||
switch (aggType) {
|
||||
case AVG:
|
||||
return new Aggregation.Builder().avg(x -> x.field(realField));
|
||||
case MIN:
|
||||
return new Aggregation.Builder().min(x -> x.field(finalName));
|
||||
case MAX:
|
||||
return new Aggregation.Builder().max(x -> x.field(realField));
|
||||
case SUM:
|
||||
return new Aggregation.Builder().sum(x -> x.field(realField));
|
||||
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 UnsupportedOperationException("不支持的聚合类型,参见AggregationTypeEnum");
|
||||
}
|
||||
return switch (aggType) {
|
||||
case AVG -> new Aggregation.Builder().avg(x -> x.field(realField));
|
||||
case MIN -> new Aggregation.Builder().min(x -> x.field(realField));
|
||||
case MAX -> new Aggregation.Builder().max(x -> x.field(realField));
|
||||
case SUM -> new Aggregation.Builder().sum(x -> x.field(realField));
|
||||
case TERMS -> new Aggregation.Builder().terms(x -> {
|
||||
x.field(realField);
|
||||
Optional.ofNullable(size).ifPresent(x::size);
|
||||
Optional.ofNullable(bucketOrders).ifPresent(x::order);
|
||||
return x;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
package org.dromara.easyes.core.toolkit;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.DistanceUnit;
|
||||
import co.elastic.clients.elasticsearch._types.GeoLocation;
|
||||
import org.dromara.easyes.common.exception.EasyEsException;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.*;
|
||||
import org.elasticsearch.geometry.utils.BitUtil;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* geo工具类
|
||||
@ -122,4 +120,204 @@ public class GeoUtils {
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT
|
||||
}
|
||||
|
||||
/**
|
||||
* geoJson 转换
|
||||
*
|
||||
* @param geometry geometry
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public static Map<String, Object> toMap(Geometry geometry) {
|
||||
Map<String, Object> root = new HashMap<>();
|
||||
root.put("type", getGeoJsonName(geometry));
|
||||
|
||||
geometry.visit(new GeometryVisitor<Void, RuntimeException>() {
|
||||
@Override
|
||||
public Void visit(Circle circle) {
|
||||
root.put("radius", circle.getRadiusMeters() + DistanceUnit.Meters.jsonValue());
|
||||
root.put("coordinates", coordinatesToList(circle.getY(), circle.getX(), circle.getZ()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GeometryCollection<?> collection) {
|
||||
List<Object> geometries = new ArrayList<>(collection.size());
|
||||
|
||||
for (Geometry g : collection) {
|
||||
geometries.add(toMap(g));
|
||||
}
|
||||
root.put("geometries", geometries);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Line line) {
|
||||
root.put("coordinates", coordinatesToList(line));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(LinearRing ring) {
|
||||
throw new UnsupportedOperationException("linearRing cannot be serialized using GeoJson");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(MultiLine multiLine) {
|
||||
List<Object> lines = new ArrayList<>(multiLine.size());
|
||||
for (int i = 0; i < multiLine.size(); i++) {
|
||||
lines.add(coordinatesToList(multiLine.get(i)));
|
||||
}
|
||||
root.put("coordinates", lines);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(MultiPoint multiPoint) {
|
||||
List<Object> points = new ArrayList<>(multiPoint.size());
|
||||
for (int i = 0; i < multiPoint.size(); i++) {
|
||||
Point p = multiPoint.get(i);
|
||||
List<Object> point = new ArrayList<>();
|
||||
point.add(p.getX());
|
||||
point.add(p.getY());
|
||||
if (p.hasZ()) {
|
||||
point.add(p.getZ());
|
||||
}
|
||||
points.add(point);
|
||||
}
|
||||
root.put("coordinates", points);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(MultiPolygon multiPolygon) {
|
||||
List<Object> polygons = new ArrayList<>();
|
||||
for (int i = 0; i < multiPolygon.size(); i++) {
|
||||
polygons.add(coordinatesToList(multiPolygon.get(i)));
|
||||
}
|
||||
root.put("coordinates", polygons);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Point point) {
|
||||
root.put("coordinates", coordinatesToList(point.getY(), point.getX(), point.getZ()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Polygon polygon) {
|
||||
List<Object> coords = new ArrayList<>(polygon.getNumberOfHoles() + 1);
|
||||
coords.add(coordinatesToList(polygon.getPolygon()));
|
||||
for (int i = 0; i < polygon.getNumberOfHoles(); i++) {
|
||||
coords.add(coordinatesToList(polygon.getHole(i)));
|
||||
}
|
||||
root.put("coordinates", coords);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Rectangle rectangle) {
|
||||
List<Object> coords = new ArrayList<>(2);
|
||||
coords.add(coordinatesToList(rectangle.getMaxY(), rectangle.getMinX(), rectangle.getMinZ())); // top left
|
||||
coords.add(coordinatesToList(rectangle.getMinY(), rectangle.getMaxX(), rectangle.getMaxZ())); // bottom right
|
||||
root.put("coordinates", coords);
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Object> coordinatesToList(double lat, double lon, double alt) {
|
||||
List<Object> coords = new ArrayList<>(3);
|
||||
coords.add(lon);
|
||||
coords.add(lat);
|
||||
if (!Double.isNaN(alt)) {
|
||||
coords.add(alt);
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
private List<Object> coordinatesToList(Line line) {
|
||||
List<Object> lines = new ArrayList<>(line.length());
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
List<Object> coords = new ArrayList<>(3);
|
||||
coords.add(line.getX(i));
|
||||
coords.add(line.getY(i));
|
||||
if (line.hasZ()) {
|
||||
coords.add(line.getZ(i));
|
||||
}
|
||||
lines.add(coords);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private List<Object> coordinatesToList(Polygon polygon) {
|
||||
List<Object> coords = new ArrayList<>(polygon.getNumberOfHoles() + 1);
|
||||
coords.add(coordinatesToList(polygon.getPolygon()));
|
||||
for (int i = 0; i < polygon.getNumberOfHoles(); i++) {
|
||||
coords.add(coordinatesToList(polygon.getHole(i)));
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取geometry名称
|
||||
*
|
||||
* @param geometry geometry
|
||||
* @return String
|
||||
*/
|
||||
public static String getGeoJsonName(Geometry geometry) {
|
||||
return geometry.visit(new GeometryVisitor<>() {
|
||||
@Override
|
||||
public String visit(Circle circle) {
|
||||
return "Circle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GeometryCollection<?> collection) {
|
||||
return "GeometryCollection";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Line line) {
|
||||
return "LineString";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(LinearRing ring) {
|
||||
throw new UnsupportedOperationException("line ring cannot be serialized using GeoJson");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(MultiLine multiLine) {
|
||||
return "MultiLineString";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(MultiPoint multiPoint) {
|
||||
return "MultiPoint";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(MultiPolygon multiPolygon) {
|
||||
return "MultiPolygon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Point point) {
|
||||
return "Point";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Polygon polygon) {
|
||||
return "Polygon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(Rectangle rectangle) {
|
||||
return "Envelope";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,6 +431,14 @@ public class IndexUtils {
|
||||
*/
|
||||
private static Map<String, Property> initInfo(EntityInfo entityInfo, GlobalConfig.DbConfig dbConfig,
|
||||
Map<String, Property> properties, List<EsIndexParam> indexParamList) {
|
||||
// 主键
|
||||
String idFieldName = entityInfo.getKeyProperty();
|
||||
if (dbConfig.isMapUnderscoreToCamelCase()) {
|
||||
idFieldName = StringUtils.camelToUnderline(idFieldName);
|
||||
}
|
||||
properties.put(idFieldName, KeywordProperty.of(a -> a)._toProperty());
|
||||
|
||||
// 其他字段
|
||||
indexParamList.forEach(indexParam -> {
|
||||
// 驼峰处理
|
||||
String fieldName = indexParam.getFieldName();
|
||||
|
||||
@ -119,7 +119,7 @@ public class Document extends BaseJoin {
|
||||
* es返回的得分字段,字段名字随便取,只要加了@Score注解即可
|
||||
*/
|
||||
@Score(decimalPlaces = 2)
|
||||
private Float score;
|
||||
private Double score;
|
||||
/**
|
||||
* es返回的距离,字段名字随便取,距离单位以用户在序器中指定的为准,不指定es默认为:米
|
||||
*/
|
||||
|
||||
@ -10,7 +10,6 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.json.JsonData;
|
||||
import co.elastic.clients.transport.rest_client.RestClientOptions;
|
||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||
import org.dromara.easyes.core.biz.EntityInfo;
|
||||
import org.dromara.easyes.core.biz.EsPageInfo;
|
||||
import org.dromara.easyes.core.biz.OrderByParam;
|
||||
@ -139,12 +138,12 @@ public class AllTest {
|
||||
wrapper.eq(Document::getTitle, "测试文档2");
|
||||
wrapper.set(Document::getContent, "测试文档内容2的内容被更新了");
|
||||
|
||||
int count = documentMapper.update(null, wrapper);
|
||||
int count = documentMapper.update(wrapper);
|
||||
Assertions.assertEquals(1, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@Order(5)
|
||||
public void testUpdateByChainWrapper() {
|
||||
int count = EsWrappers.lambdaChainUpdate(documentMapper)
|
||||
.eq(Document::getTitle, "测试文档3")
|
||||
@ -154,16 +153,16 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@Order(6)
|
||||
public void testUpdateBySetSearchSourceBuilder() {
|
||||
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(QueryBuilders.term()
|
||||
SearchRequest.Builder searchBuilder = new SearchRequest.Builder();
|
||||
searchBuilder.query(QueryBuilders.term()
|
||||
.field(FieldUtils.val(Document::getTitle) + KEYWORD_SUFFIX)
|
||||
.value("测试文档2")
|
||||
.build()._toQuery()
|
||||
);
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchBuilder);
|
||||
|
||||
Document document = new Document();
|
||||
document.setContent("测试文档内容2的内容再次被更新了");
|
||||
@ -172,7 +171,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@Order(7)
|
||||
public void testUpdateByWrapperAndEntity() {
|
||||
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -185,7 +184,7 @@ public class AllTest {
|
||||
// 3.查询
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(8)
|
||||
public void testSQL() {
|
||||
// 注意 sql中的from后面跟的是要被查询的索引名,也可以是索引别名(效果一样) 由于索引名可能会变,所以此处我采用别名ee_default_alias进行查询
|
||||
String sql = "select count(*) from ee_default_alias where star_num > 0";
|
||||
@ -195,7 +194,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(9)
|
||||
public void testDSL() {
|
||||
String dsl = "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"title.keyword\":{\"value\":\"测试文档3\",\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"track_total_hits\":2147483647,\"highlight\":{\"pre_tags\":[\"<em>\"],\"post_tags\":[\"</em>\"],\"fragment_size\":2,\"fields\":{\"content\":{\"type\":\"unified\"}}}}";
|
||||
String jsonResult = documentMapper.executeDSL(dsl);
|
||||
@ -204,7 +203,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(10)
|
||||
public void testSelectOne() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "内容")
|
||||
@ -215,7 +214,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(11)
|
||||
public void testOne() {
|
||||
// 链式调用
|
||||
Document document = EsWrappers.lambdaChainQuery(documentMapper).eq(Document::getTitle, "测试文档3").one();
|
||||
@ -223,14 +222,14 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(12)
|
||||
public void testDefaultMethod() {
|
||||
List<Document> documents = documentMapper.testDefaultMethod();
|
||||
Assertions.assertEquals(documents.size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(13)
|
||||
public void testSelectById() {
|
||||
Document document = documentMapper.selectById(1);
|
||||
Assertions.assertEquals("1", document.getEsId());
|
||||
@ -238,14 +237,14 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(14)
|
||||
public void testSelectBatchIds() {
|
||||
List<Document> documents = documentMapper.selectBatchIds(Arrays.asList("1", "2"));
|
||||
Assertions.assertEquals(2, documents.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(15)
|
||||
public void testSelectList() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCustomField, "字段");
|
||||
@ -254,7 +253,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(16)
|
||||
public void testIgnoreCase() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getCaseTest, "test");
|
||||
@ -263,7 +262,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(17)
|
||||
public void testIp() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getIpAddress, "192.168.0.0/16");
|
||||
@ -272,7 +271,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(18)
|
||||
public void testSelectCount() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCustomField, "字段");
|
||||
@ -281,7 +280,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(19)
|
||||
public void testSelectCountDistinct() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCustomField, "字段");
|
||||
@ -291,7 +290,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(20)
|
||||
public void testConditionAllEq() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@ -305,7 +304,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(21)
|
||||
public void testConditionEq() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, "测试文档10");
|
||||
@ -315,7 +314,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(22)
|
||||
public void testConditionGt() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.gt(Document::getStarNum, 20);
|
||||
@ -324,7 +323,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(23)
|
||||
public void testConditionGe() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.ge(Document::getStarNum, 20);
|
||||
@ -333,7 +332,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(24)
|
||||
public void testConditionLt() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.lt(Document::getStarNum, 3);
|
||||
@ -342,7 +341,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(25)
|
||||
public void testConditionLe() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.le(Document::getStarNum, 3);
|
||||
@ -351,7 +350,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(26)
|
||||
public void testConditionBetween() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.between(Document::getStarNum, 1, 10);
|
||||
@ -360,7 +359,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(27)
|
||||
public void testConditionLike() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.like(Document::getTitle, "试文档");
|
||||
@ -369,7 +368,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(28)
|
||||
public void testConditionLikeLeft() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.likeLeft(Document::getTitle, "文档10");
|
||||
@ -378,7 +377,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(29)
|
||||
public void testConditionLikeRight() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.likeRight(Document::getTitle, "测试文");
|
||||
@ -387,7 +386,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(30)
|
||||
public void testConditionIsNotNull() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.isNotNull(Document::getNullField);
|
||||
@ -396,7 +395,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(31)
|
||||
public void testConditionExists() {
|
||||
// exists等价于isNotNull 在es中更推荐此种语法
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
@ -405,9 +404,8 @@ public class AllTest {
|
||||
Assertions.assertEquals(1, documents.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(32)
|
||||
public void testConditionIn() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.in(Document::getEsId, "1", "2", "3");
|
||||
@ -421,7 +419,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(33)
|
||||
public void testConditionGroupBy() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
@ -433,53 +431,51 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(34)
|
||||
public void testConditionMax() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
.max(Document::getStarNum);
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
Aggregate agg = response.aggregations().get("starNumMax");
|
||||
Assertions.assertTrue(agg.valueCount().value() > 21);
|
||||
Assertions.assertTrue(agg.max().value() > 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(35)
|
||||
public void testConditionMin() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
.min(Document::getStarNum);
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
double parsedMin = response.aggregations().get("starNumMin").valueCount().value();
|
||||
double parsedMin = response.aggregations().get("starNumMin").min().value();
|
||||
Assertions.assertTrue(parsedMin > 0 && parsedMin < 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(36)
|
||||
public void testConditionSum() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
.sum(Document::getStarNum);
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
double parsedSum = response.aggregations().get("starNumSum").valueCount().value();
|
||||
double parsedSum = response.aggregations().get("starNumSum").sum().value();
|
||||
Assertions.assertTrue(parsedSum >= 252);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(37)
|
||||
public void testConditionAvg() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
.avg(Document::getStarNum);
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
double parsedAvg = response.aggregations().get("starNumAvg").valueCount().value();
|
||||
double parsedAvg = response.aggregations().get("starNumAvg").avg().value();
|
||||
Assertions.assertTrue(parsedAvg > 11 && parsedAvg < 12);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(38)
|
||||
public void testConditionDistinct() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
@ -489,7 +485,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(39)
|
||||
public void testConditionLimit() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉")
|
||||
@ -499,7 +495,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(40)
|
||||
public void testConditionFromAndSize() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉")
|
||||
@ -510,7 +506,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(41)
|
||||
public void testConditionIndex() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉")
|
||||
@ -520,7 +516,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(42)
|
||||
public void testSetSearchSourceBuilder() {
|
||||
EntityInfo e = EntityInfoHelper.getEntityInfo(Document.class);
|
||||
// 测试混合查询的另一种方式
|
||||
@ -532,13 +528,13 @@ public class AllTest {
|
||||
)
|
||||
.size(e.getMaxResultWindow().intValue());
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertEquals(22, documents.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(43)
|
||||
public void testConditionAnd() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.in(Document::getStarNum, 1, 2, 3, 4, 10, 11)
|
||||
@ -548,7 +544,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(44)
|
||||
public void testConditionOr() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.in(Document::getStarNum, 1, 10, 12, 13)
|
||||
@ -558,7 +554,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(45)
|
||||
public void testConditionOrInner() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, "测试文档10")
|
||||
@ -569,7 +565,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(46)
|
||||
public void testConditionFilter() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getStarNum, 10)
|
||||
@ -579,7 +575,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(47)
|
||||
public void testConditionNot() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.in(Document::getStarNum, 10, 11, 12, 13)
|
||||
@ -588,9 +584,8 @@ public class AllTest {
|
||||
Assertions.assertEquals(2, documents.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(48)
|
||||
public void testPageQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -600,7 +595,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(49)
|
||||
public void testChainPage() {
|
||||
// 链式
|
||||
EsPageInfo<Document> pageInfo = EsWrappers.lambdaChainQuery(documentMapper)
|
||||
@ -610,9 +605,8 @@ public class AllTest {
|
||||
Assertions.assertEquals(22, pageInfo.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(50)
|
||||
public void testSearchAfter() {
|
||||
LambdaEsQueryWrapper<Document> lambdaEsQueryWrapper = EsWrappers.lambdaQuery(Document.class);
|
||||
lambdaEsQueryWrapper.size(10);
|
||||
@ -629,7 +623,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(51)
|
||||
public void testFilterField() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, "测试文档10")
|
||||
@ -641,7 +635,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(52)
|
||||
public void testNotFilterField() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.eq(Document::getTitle, "测试文档10")
|
||||
@ -653,7 +647,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(53)
|
||||
public void testOrderByDesc() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -664,7 +658,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(54)
|
||||
public void testOrderByAsc() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -675,7 +669,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(55)
|
||||
public void testOrderBy() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -691,7 +685,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(56)
|
||||
public void testOrderByDistanceAsc() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
GeoLocation centerPoint = GeoLocation.of(a -> a.latlon(a1 -> a1.lat(41.0).lon(116.0)));
|
||||
@ -704,7 +698,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(57)
|
||||
public void testOrderByDistanceDesc() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
GeoLocation centerPoint = GeoLocation.of(a -> a.latlon(a1 -> a1.lat(41.0).lon(116.0)));
|
||||
@ -717,7 +711,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(58)
|
||||
public void testOrderByDistanceMulti() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
GeoLocation centerPoint = GeoLocation.of(a -> a.latlon(a1 -> a1.lat(41.0).lon(116.0)));
|
||||
@ -732,7 +726,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(59)
|
||||
public void testSortByScore() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉11");
|
||||
@ -742,7 +736,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(60)
|
||||
public void testSort() {
|
||||
String realField = FieldUtils.getRealField(
|
||||
FieldUtils.val(Document::getStarNum),
|
||||
@ -761,7 +755,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(61)
|
||||
public void testMatch() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
@ -770,7 +764,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(62)
|
||||
public void testMatchPhrase() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.matchPhrase(Document::getContent, "测试");
|
||||
@ -784,7 +778,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(63)
|
||||
public void testMatchAllQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.matchAllQuery();
|
||||
@ -793,7 +787,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(64)
|
||||
public void testMatchPhrasePrefixQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.matchPhrasePrefixQuery(Document::getContent, "测试");
|
||||
@ -802,7 +796,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(65)
|
||||
public void testMultiMatchQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.multiMatchQuery("老汉", Document::getContent, Document::getCreator, Document::getCustomField);
|
||||
@ -817,7 +811,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(66)
|
||||
public void testQueryStringQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.queryStringQuery("老汉");
|
||||
@ -826,7 +820,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(67)
|
||||
public void testPrefixQuery() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.prefixQuery(Document::getContent, "测试");
|
||||
@ -835,7 +829,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(68)
|
||||
public void testHighLight() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getContent, "测试")
|
||||
@ -845,7 +839,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(69)
|
||||
public void testGeoBoundingBox() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
GeoLocation leftTop = GeoLocation.of(a -> a.latlon(a1 -> a1.lat(41.187328D).lon(115.498353D)));
|
||||
@ -855,9 +849,8 @@ public class AllTest {
|
||||
Assertions.assertEquals(4, documents.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(70)
|
||||
public void testGeoDistance() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
GeoLocation geoPoint = GeoLocation.of(a -> a.latlon(a1 -> a1.lat(41.0).lon(116.0)));
|
||||
@ -874,7 +867,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(71)
|
||||
public void testGeoPolygon() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
List<GeoLocation> geoPoints = new ArrayList<>();
|
||||
@ -890,7 +883,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(72)
|
||||
public void testGeoShape() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
Circle circle = new Circle(13, 14, 100);
|
||||
@ -900,7 +893,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(73)
|
||||
public void testMultiFieldSelect() {
|
||||
// 药品 中文名叫葡萄糖酸钙口服溶液 英文名叫 Calcium Gluconate 汉语拼音为 putaotangsuangaikoufurongye
|
||||
// 用户可以通过模糊检索,例如输入 Calcium 或 葡萄糖 或 putaotang时对应药品均可以被检索到
|
||||
@ -915,7 +908,7 @@ public class AllTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(74)
|
||||
public void testVector() {
|
||||
// 向量查询, 查询条件构造
|
||||
Query query = Query.of(a -> a.scriptScore(b -> b
|
||||
@ -929,14 +922,14 @@ public class AllTest {
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(query);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
List<Document> Documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertFalse(Documents.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(75)
|
||||
public void testSetRequestOptions() {
|
||||
// 可设置自定义请求参数,覆盖默认配置, 解决报错 entity content is too long [168583249] for the configured buffer limit [104857600]
|
||||
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
||||
@ -947,42 +940,42 @@ public class AllTest {
|
||||
}
|
||||
|
||||
// 4.删除
|
||||
@Test
|
||||
@Order(7)
|
||||
public void testDeleteById() {
|
||||
int count = documentMapper.deleteById("1");
|
||||
Assertions.assertEquals(1, count);
|
||||
}
|
||||
// @Test
|
||||
// @Order(76)
|
||||
// public void testDeleteById() {
|
||||
// int count = documentMapper.deleteById("1");
|
||||
// Assertions.assertEquals(1, count);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(77)
|
||||
// public void testDeleteBatchIds() {
|
||||
// List<String> idList = Arrays.asList("2", "3", "4");
|
||||
// int count = documentMapper.deleteBatchIds(idList);
|
||||
// Assertions.assertEquals(3, count);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(78)
|
||||
// public void testDeleteByWrapper() {
|
||||
// LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
// wrapper.match(Document::getCreator, "老汉");
|
||||
//
|
||||
// int count = documentMapper.delete(wrapper);
|
||||
// Assertions.assertEquals(18, count);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(80)
|
||||
// public void testDeleteIndex() {
|
||||
// boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName());
|
||||
// boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX);
|
||||
// Assertions.assertTrue(deleted);
|
||||
// Assertions.assertTrue(lockDeleted);
|
||||
// }
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void testDeleteBatchIds() {
|
||||
List<String> idList = Arrays.asList("2", "3", "4");
|
||||
int count = documentMapper.deleteBatchIds(idList);
|
||||
Assertions.assertEquals(3, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void testDeleteByWrapper() {
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.match(Document::getCreator, "老汉");
|
||||
|
||||
int count = documentMapper.delete(wrapper);
|
||||
Assertions.assertEquals(18, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void testDeleteIndex() {
|
||||
boolean deleted = documentMapper.deleteIndex(EntityInfoHelper.getEntityInfo(Document.class).getIndexName());
|
||||
boolean lockDeleted = documentMapper.deleteIndex(BaseEsConstants.LOCK_INDEX);
|
||||
Assertions.assertTrue(deleted);
|
||||
Assertions.assertTrue(lockDeleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@Order(79)
|
||||
public void testComplex() {
|
||||
// SQL写法
|
||||
// where business_type = 1 and (state = 9 or (state = 8 and bidding_sign = 1)) or (business_type = 2 and state in (2,3))
|
||||
|
||||
@ -169,7 +169,7 @@ public class XmlScannerAllTest {
|
||||
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(QueryBuilders.termQuery(FieldUtils.val(Document::getTitle) + KEYWORD_SUFFIX, "测试文档2"));
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
Document document = new Document();
|
||||
document.setContent("测试文档内容2的内容再次被更新了");
|
||||
@ -540,7 +540,7 @@ public class XmlScannerAllTest {
|
||||
.flatMap(i -> Optional.ofNullable(i.getMaxResultWindow()))
|
||||
.ifPresent(searchSourceBuilder::size);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertEquals(22, documents.size());
|
||||
}
|
||||
@ -930,7 +930,7 @@ public class XmlScannerAllTest {
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
List<Document> Documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertFalse(Documents.isEmpty());
|
||||
|
||||
@ -171,7 +171,7 @@ public class AllTest {
|
||||
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(QueryBuilders.termQuery(FieldUtils.val(Document::getTitle) + KEYWORD_SUFFIX, "测试文档2"));
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
Document document = new Document();
|
||||
document.setContent("测试文档内容2的内容再次被更新了");
|
||||
@ -542,7 +542,7 @@ public class AllTest {
|
||||
.flatMap(i -> Optional.ofNullable(i.getMaxResultWindow()))
|
||||
.ifPresent(searchSourceBuilder::size);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertEquals(22, documents.size());
|
||||
}
|
||||
@ -932,7 +932,7 @@ public class AllTest {
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
List<Document> Documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertFalse(Documents.isEmpty());
|
||||
|
||||
@ -73,7 +73,7 @@ public class MixTest {
|
||||
|
||||
// 仅利用EE查询并解析数据功能
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class MixTest {
|
||||
|
||||
// 追加或者设置一些SearchSourceBuilder支持但EE暂不支持的参数 不建议追加query参数,因为如果追加query参数会直接覆盖上面EE已经帮你生成好的query,以最后set的query为准
|
||||
searchSourceBuilder.timeout(TimeValue.timeValueSeconds(3L));
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class MixTest {
|
||||
AggregationBuilder aggregation = AggregationBuilders.terms("titleAgg")
|
||||
.field("title");
|
||||
searchSourceBuilder.aggregation(aggregation);
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
SearchResponse searchResponse = documentMapper.search(wrapper);
|
||||
// tip: 聚合后的信息是动态的,框架无法解析,需要用户根据聚合器类型自行从桶中解析,参考ElasticsearchClient官方Aggregation解析文档
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class MixTest {
|
||||
|
||||
// 用户又想在上面的基础上,再追加一些个性化的查询参数进去 但实际上此时执行查询时,查询条件仅仅是最后设置的title=隔壁老王,前面的老汉推*会被覆盖
|
||||
searchSourceBuilder.query(QueryBuilders.matchQuery("title", "隔壁老王"));
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
// 思考: 为什么会被覆盖? 因为目前技术上做不到,查询树已经建立好了,es底层并没有提供向树的指定层级上继续追加查询条件的API
|
||||
@ -171,7 +171,7 @@ public class MixTest {
|
||||
// SearchSourceBuilder的构造是自己new出来的,不是通过mapper.getSearchSourceBuilder(wrapper)构造 相当于脱裤子放P,那么上面的查询条件老汉推*自然不会生效
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.minScore(10.5);
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ public class VectorTest {
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.setSearchSourceBuilder(searchSourceBuilder);
|
||||
wrapper.setSearchBuilder(searchSourceBuilder);
|
||||
|
||||
List<Document> Documents = documentMapper.selectList(wrapper);
|
||||
Assertions.assertFalse(Documents.isEmpty());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user