mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-06 17:18:57 +08:00
feat: jdk8 es-java7.17.28
This commit is contained in:
parent
7d8e879b4b
commit
6fa0acb175
@ -194,7 +194,7 @@ public class EntityInfo {
|
||||
/**
|
||||
* 请求配置 默认值为官方内置的默认配置
|
||||
*/
|
||||
private TransportOptions requestOptions = new RestClientOptions(RequestOptions.DEFAULT, true);
|
||||
private TransportOptions requestOptions = new RestClientOptions(RequestOptions.DEFAULT);
|
||||
/**
|
||||
* 最大返回数
|
||||
*/
|
||||
|
||||
@ -324,8 +324,7 @@ public class IndexUtils {
|
||||
.source(mappings.source())
|
||||
.runtime(mappings.runtime())
|
||||
.enabled(mappings.enabled())
|
||||
.subobjects(mappings.subobjects())
|
||||
.dataStreamTimestamp(mappings.dataStreamTimestamp());
|
||||
;
|
||||
esIndexInfo.setMapping(builder);
|
||||
}
|
||||
|
||||
@ -418,7 +417,7 @@ public class IndexUtils {
|
||||
if (CollectionUtils.isNotEmpty(entityInfo.getRelationMap())) {
|
||||
mapping.properties(entityInfo.getJoinFieldName(), x -> x.join(y -> y
|
||||
.relations(entityInfo.getRelationMap())
|
||||
.eagerGlobalOrdinals(entityInfo.isEagerGlobalOrdinals())
|
||||
// .eagerGlobalOrdinals(entityInfo.isEagerGlobalOrdinals())
|
||||
));
|
||||
}
|
||||
|
||||
@ -455,7 +454,6 @@ public class IndexUtils {
|
||||
|
||||
if (FieldType.BYTE.getType().equals(indexParam.getFieldType())) {
|
||||
ByteNumberProperty property = ByteNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -465,7 +463,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.SHORT.getType().equals(indexParam.getFieldType())) {
|
||||
ShortNumberProperty property = ShortNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -475,7 +472,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.INTEGER.getType().equals(indexParam.getFieldType())) {
|
||||
IntegerNumberProperty property = IntegerNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -485,7 +481,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.LONG.getType().equals(indexParam.getFieldType())) {
|
||||
LongNumberProperty property = LongNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -495,7 +490,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.FLOAT.getType().equals(indexParam.getFieldType())) {
|
||||
FloatNumberProperty property = FloatNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -505,7 +499,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.DOUBLE.getType().equals(indexParam.getFieldType())) {
|
||||
DoubleNumberProperty property = DoubleNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -515,7 +508,6 @@ public class IndexUtils {
|
||||
}
|
||||
if (FieldType.HALF_FLOAT.getType().equals(indexParam.getFieldType())) {
|
||||
HalfFloatNumberProperty property = HalfFloatNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
return a;
|
||||
@ -527,7 +519,6 @@ public class IndexUtils {
|
||||
Double scalingFactor = Optional.ofNullable(indexParam.getScalingFactor())
|
||||
.map(NumericUtils::formatNumberWithOneDecimal).orElse(DEFAULT_SCALING_FACTOR);
|
||||
ScaledFloatNumberProperty property = ScaledFloatNumberProperty.of(a -> {
|
||||
a.boost(indexParam.getBoost());
|
||||
buildCopyTo(a, entityInfo.isIndexEqualStage(), indexParam.getCopyToList());
|
||||
buildInnerFields(a, indexParam);
|
||||
a.scalingFactor(scalingFactor);
|
||||
|
||||
@ -2,17 +2,17 @@ package org.dromara.easyes.core.toolkit;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.json.JsonpMapper;
|
||||
import co.elastic.clients.json.JsonpUtils;
|
||||
import co.elastic.clients.json.NdJsonpSerializable;
|
||||
import co.elastic.clients.transport.ElasticsearchTransportBase;
|
||||
import co.elastic.clients.transport.Endpoint;
|
||||
import co.elastic.clients.util.BinaryData;
|
||||
import jakarta.json.stream.JsonGenerator;
|
||||
import org.dromara.easyes.common.property.GlobalConfig;
|
||||
import org.dromara.easyes.common.utils.LogUtils;
|
||||
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@ -114,7 +114,10 @@ public class PrintUtils {
|
||||
for (Map.Entry<String, String> param : params.entrySet()) {
|
||||
fullUrlSb.append(delim);
|
||||
delim = "&";
|
||||
fullUrlSb.append(param.getKey()).append("=").append(URLEncoder.encode(param.getValue(), StandardCharsets.UTF_8));
|
||||
try {
|
||||
fullUrlSb.append(param.getKey()).append("=").append(URLEncoder.encode(param.getValue(), "UTF-8"));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
return fullUrlSb.toString();
|
||||
}
|
||||
@ -135,7 +138,7 @@ public class PrintUtils {
|
||||
}
|
||||
|
||||
if (!(body instanceof NdJsonpSerializable)) {
|
||||
return JsonpUtils.toJsonString(body, mapper);
|
||||
return toJsonString(body, mapper);
|
||||
}
|
||||
NdJsonpSerializable nd = (NdJsonpSerializable) body;
|
||||
|
||||
@ -161,8 +164,16 @@ public class PrintUtils {
|
||||
NdJsonpSerializable nd = (NdJsonpSerializable) item; // do not recurse on the item itself
|
||||
collectNdJsonLines(body, nd, mapper);
|
||||
} else {
|
||||
body.append(JsonpUtils.toJsonString(item, mapper)).append("\n");
|
||||
body.append(toJsonString(item, mapper)).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String toJsonString(Object value, JsonpMapper mapper) {
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonGenerator generator = mapper.jsonProvider().createGenerator(writer);
|
||||
mapper.serialize(value, generator);
|
||||
generator.close();
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ public class MySettingsProvider extends DefaultSettingsProvider {
|
||||
|
||||
@Override
|
||||
public void settings(IndexSettings.Builder builder) {
|
||||
builder.index(a -> a.search(b -> b
|
||||
.slowlog(c -> c.threshold(d -> d.query(e -> e.warn(f -> f.time("30s")))))));
|
||||
builder.index(a -> a.indexingSlowlog(b -> b
|
||||
.threshold(c -> c.query(d -> d.warn(e -> e.time("30s"))))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ public class AllTest {
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
Aggregate aggregate = response.aggregations().get("starNumTerms");
|
||||
LongTermsBucket bucket = aggregate.lterms().buckets().array().get(0);
|
||||
Assertions.assertTrue(bucket.key() == 1L && bucket.docCount() == 2L);
|
||||
Assertions.assertTrue(bucket.key().equals("1") && bucket.docCount() == 2L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -915,11 +915,11 @@ public class AllTest {
|
||||
// 向量查询, 查询条件构造
|
||||
Query query = Query.of(a -> a.scriptScore(b -> b
|
||||
.query(QueryBuilders.matchAll().build()._toQuery())
|
||||
.script(d -> d
|
||||
.lang(ScriptLanguage.Painless)
|
||||
.script(d -> d.inline(e -> e
|
||||
.lang("painless")
|
||||
.params("vector", JsonData.of(new double[]{0.39684247970581055, 0.7687071561813354, 0.5145490765571594}))
|
||||
.source("cosineSimilarity(params.vector, 'vector') + 1.0")
|
||||
)
|
||||
))
|
||||
));
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(query);
|
||||
@ -937,7 +937,7 @@ public class AllTest {
|
||||
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
||||
builder.setHttpAsyncResponseConsumerFactory(
|
||||
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(4 * 104857600));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build(), true));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build()));
|
||||
Assertions.assertTrue(success);
|
||||
}
|
||||
|
||||
|
||||
@ -427,7 +427,7 @@ public class XmlScannerAllTest {
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
Aggregate aggregate = response.aggregations().get("starNumTerms");
|
||||
LongTermsBucket bucket = aggregate.lterms().buckets().array().get(0);
|
||||
Assertions.assertTrue(bucket.key() == 1L && bucket.docCount() == 2L);
|
||||
Assertions.assertTrue(bucket.key().equals("1") && bucket.docCount() == 2L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -914,11 +914,11 @@ public class XmlScannerAllTest {
|
||||
// 向量查询, 查询条件构造
|
||||
Query query = Query.of(a -> a.scriptScore(b -> b
|
||||
.query(QueryBuilders.matchAll().build()._toQuery())
|
||||
.script(d -> d
|
||||
.lang(ScriptLanguage.Painless)
|
||||
.script(d -> d.inline(e -> e
|
||||
.lang("painless")
|
||||
.params("vector", JsonData.of(new double[]{0.39684247970581055, 0.7687071561813354, 0.5145490765571594}))
|
||||
.source("cosineSimilarity(params.vector, 'vector') + 1.0")
|
||||
)
|
||||
))
|
||||
));
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(query);
|
||||
@ -936,7 +936,7 @@ public class XmlScannerAllTest {
|
||||
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
||||
builder.setHttpAsyncResponseConsumerFactory(
|
||||
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(4 * 104857600));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build(), true));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build()));
|
||||
Assertions.assertTrue(success);
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import org.dromara.easyes.annotation.rely.DefaultSettingsProvider;
|
||||
public class MySettingsProvider extends DefaultSettingsProvider {
|
||||
@Override
|
||||
public void settings(IndexSettings.Builder builder) {
|
||||
builder.index(a -> a.search(b -> b
|
||||
.slowlog(c -> c.threshold(d -> d.query(e -> e.warn(f -> f.time("30s")))))));
|
||||
builder.index(a -> a.indexingSlowlog(b -> b
|
||||
.threshold(c -> c.query(d -> d.warn(e -> e.time("30s"))))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import org.dromara.easyes.annotation.rely.DefaultSettingsProvider;
|
||||
public class MySettingsProvider extends DefaultSettingsProvider {
|
||||
@Override
|
||||
public void settings(IndexSettings.Builder builder) {
|
||||
builder.index(a -> a.search(b -> b
|
||||
.slowlog(c -> c.threshold(d -> d.query(e -> e.warn(f -> f.time("30s")))))));
|
||||
builder.index(a -> a.indexingSlowlog(b -> b
|
||||
.threshold(c -> c.query(d -> d.warn(e -> e.time("30s"))))));
|
||||
}
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ public class AllTest {
|
||||
SearchResponse<Document> response = documentMapper.search(wrapper);
|
||||
Aggregate aggregate = response.aggregations().get("starNumTerms");
|
||||
LongTermsBucket bucket = aggregate.lterms().buckets().array().get(0);
|
||||
Assertions.assertTrue(bucket.key() == 1L && bucket.docCount() == 2L);
|
||||
Assertions.assertTrue(bucket.key().equals("1") && bucket.docCount() == 2L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -916,11 +916,11 @@ public class AllTest {
|
||||
// 向量查询, 查询条件构造
|
||||
Query query = Query.of(a -> a.scriptScore(b -> b
|
||||
.query(QueryBuilders.matchAll().build()._toQuery())
|
||||
.script(d -> d
|
||||
.lang(ScriptLanguage.Painless)
|
||||
.script(d -> d.inline(e -> e
|
||||
.lang("painless")
|
||||
.params("vector", JsonData.of(new double[]{0.39684247970581055, 0.7687071561813354, 0.5145490765571594}))
|
||||
.source("cosineSimilarity(params.vector, 'vector') + 1.0")
|
||||
)
|
||||
))
|
||||
));
|
||||
SearchRequest.Builder searchSourceBuilder = new SearchRequest.Builder();
|
||||
searchSourceBuilder.query(query);
|
||||
@ -938,7 +938,7 @@ public class AllTest {
|
||||
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
||||
builder.setHttpAsyncResponseConsumerFactory(
|
||||
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(4 * 104857600));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build(), true));
|
||||
Boolean success = documentMapper.setRequestOptions(new RestClientOptions(builder.build()));
|
||||
Assertions.assertTrue(success);
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ public class CompareTest {
|
||||
@Autowired
|
||||
private ElasticsearchClient client;
|
||||
|
||||
public static RestClientOptions options = new RestClientOptions(RequestOptions.DEFAULT, true);
|
||||
public static RestClientOptions options = new RestClientOptions(RequestOptions.DEFAULT);
|
||||
|
||||
@Test
|
||||
public void testCompare() {
|
||||
|
||||
@ -171,7 +171,7 @@ public class HighTest {
|
||||
wrapper.match(Document::getContent, "技术");
|
||||
wrapper.sort(SortOptions.of(a -> a.script(b -> b
|
||||
.type(ScriptSortType.Number)
|
||||
.script(c -> c.source("Math.random()"))
|
||||
.script(c -> c.inline(e -> e.source("Math.random()")))
|
||||
)));
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
|
||||
@ -97,7 +97,7 @@ public class MixTest {
|
||||
wrapper.sort(SortOptions.of(a -> a.script(b -> b
|
||||
.type(ScriptSortType.Number)
|
||||
.order(SortOrder.Desc)
|
||||
.script(c -> c.source("doc['star_num'].value"))
|
||||
.script(c -> c.inline(e -> e.source("doc['star_num'].value")))
|
||||
)));
|
||||
List<Document> documents = documentMapper.selectList(wrapper);
|
||||
System.out.println(documents);
|
||||
|
||||
@ -18,6 +18,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.dromara.easyes.common.constants.BaseEsConstants.DEFAULT_SIZE;
|
||||
|
||||
@ -82,8 +83,7 @@ public class PerformanceTest {
|
||||
|
||||
List<Document> documents = search.hits().hits().stream()
|
||||
.map(Hit::source)
|
||||
.toList();
|
||||
|
||||
.collect(Collectors.toList());
|
||||
SearchRequest countRequest = SearchRequest.of(a -> a.index("kiplatform_library"));
|
||||
SearchResponse<Document> countResponse = null;
|
||||
try {
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package org.dromara.easyes.test.vector;
|
||||
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.ScriptLanguage;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
@ -54,11 +52,11 @@ public class VectorTest {
|
||||
public void testVectorSearch() {
|
||||
Query query = Query.of(a -> a.scriptScore(b -> b
|
||||
.query(QueryBuilders.matchAll().build()._toQuery())
|
||||
.script(d -> d
|
||||
.lang(ScriptLanguage.Painless)
|
||||
.script(d -> d.inline(e -> e
|
||||
.lang("painless")
|
||||
.params("vector", JsonData.of(new double[]{0.39684247970581055, 0.7687071561813354, 0.5145490765571594}))
|
||||
.source("cosineSimilarity(params.vector, 'vector') + 1.0")
|
||||
)
|
||||
))
|
||||
));
|
||||
|
||||
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user