mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-01 09:42:11 +00:00
es java client major update.
Original Pull Request #3116 Closes #3110 Signed-off-by: Laura Trotta <laura.trotta@elastic.co>
This commit is contained in:
parent
6268133506
commit
158f5fc342
2
pom.xml
2
pom.xml
@ -21,7 +21,7 @@
|
|||||||
<springdata.commons>4.0.0-SNAPSHOT</springdata.commons>
|
<springdata.commons>4.0.0-SNAPSHOT</springdata.commons>
|
||||||
|
|
||||||
<!-- version of the ElasticsearchClient -->
|
<!-- version of the ElasticsearchClient -->
|
||||||
<elasticsearch-java>8.18.1</elasticsearch-java>
|
<elasticsearch-java>9.0.1</elasticsearch-java>
|
||||||
|
|
||||||
<hoverfly>0.19.0</hoverfly>
|
<hoverfly>0.19.0</hoverfly>
|
||||||
<log4j>2.23.1</log4j>
|
<log4j>2.23.1</log4j>
|
||||||
|
@ -83,7 +83,7 @@ final class DocumentAdapters {
|
|||||||
|
|
||||||
Explanation explanation = from(hit.explanation());
|
Explanation explanation = from(hit.explanation());
|
||||||
|
|
||||||
List<String> matchedQueries = hit.matchedQueries();
|
Map<String, Double> matchedQueries = hit.matchedQueries();
|
||||||
|
|
||||||
Function<Map<String, JsonData>, EntityAsMap> fromFields = fields -> {
|
Function<Map<String, JsonData>, EntityAsMap> fromFields = fields -> {
|
||||||
StringBuilder sb = new StringBuilder("{");
|
StringBuilder sb = new StringBuilder("{");
|
||||||
|
@ -539,14 +539,6 @@ public class ReactiveElasticsearchIndicesClient
|
|||||||
return stats(builder -> builder);
|
return stats(builder -> builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<UnfreezeResponse> unfreeze(UnfreezeRequest request) {
|
|
||||||
return Mono.fromFuture(transport.performRequestAsync(request, UnfreezeRequest._ENDPOINT, transportOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<UnfreezeResponse> unfreeze(Function<UnfreezeRequest.Builder, ObjectBuilder<UnfreezeRequest>> fn) {
|
|
||||||
return unfreeze(fn.apply(new UnfreezeRequest.Builder()).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<UpdateAliasesResponse> updateAliases(UpdateAliasesRequest request) {
|
public Mono<UpdateAliasesResponse> updateAliases(UpdateAliasesRequest request) {
|
||||||
return Mono.fromFuture(transport.performRequestAsync(request, UpdateAliasesRequest._ENDPOINT, transportOptions));
|
return Mono.fromFuture(transport.performRequestAsync(request, UpdateAliasesRequest._ENDPOINT, transportOptions));
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ import co.elastic.clients.elasticsearch.core.bulk.CreateOperation;
|
|||||||
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
|
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
|
||||||
import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation;
|
import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation;
|
||||||
import co.elastic.clients.elasticsearch.core.mget.MultiGetOperation;
|
import co.elastic.clients.elasticsearch.core.mget.MultiGetOperation;
|
||||||
import co.elastic.clients.elasticsearch.core.msearch.MultisearchBody;
|
|
||||||
import co.elastic.clients.elasticsearch.core.msearch.MultisearchHeader;
|
import co.elastic.clients.elasticsearch.core.msearch.MultisearchHeader;
|
||||||
import co.elastic.clients.elasticsearch.core.search.Highlight;
|
import co.elastic.clients.elasticsearch.core.search.Highlight;
|
||||||
import co.elastic.clients.elasticsearch.core.search.Rescore;
|
import co.elastic.clients.elasticsearch.core.search.Rescore;
|
||||||
|
import co.elastic.clients.elasticsearch.core.search.SearchRequestBody;
|
||||||
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
|
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
|
||||||
import co.elastic.clients.elasticsearch.indices.*;
|
import co.elastic.clients.elasticsearch.indices.*;
|
||||||
import co.elastic.clients.elasticsearch.indices.ExistsIndexTemplateRequest;
|
import co.elastic.clients.elasticsearch.indices.ExistsIndexTemplateRequest;
|
||||||
@ -751,11 +751,10 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
}
|
}
|
||||||
return co.elastic.clients.elasticsearch._types.Script.of(sb -> {
|
return co.elastic.clients.elasticsearch._types.Script.of(sb -> {
|
||||||
sb.lang(scriptData.language())
|
sb.lang(scriptData.language())
|
||||||
.params(params);
|
.params(params)
|
||||||
if (scriptData.type() == ScriptType.INLINE) {
|
.id(scriptData.scriptName());
|
||||||
sb.source(scriptData.script());
|
if (scriptData.script() != null){
|
||||||
} else if (scriptData.type() == ScriptType.STORED) {
|
sb.source(s -> s.scriptString(scriptData.script()));
|
||||||
sb.id(scriptData.script());
|
|
||||||
}
|
}
|
||||||
return sb;
|
return sb;
|
||||||
});
|
});
|
||||||
@ -927,9 +926,13 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
|
|
||||||
ReindexRequest.Script script = reindexRequest.getScript();
|
ReindexRequest.Script script = reindexRequest.getScript();
|
||||||
if (script != null) {
|
if (script != null) {
|
||||||
builder.script(sb -> sb
|
builder.script(sb -> {
|
||||||
.lang(script.getLang())
|
if (script.getSource() != null){
|
||||||
.source(script.getSource()));
|
sb.source(s -> s.scriptString(script.getSource()));
|
||||||
|
}
|
||||||
|
sb.lang(script.getLang());
|
||||||
|
return sb;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.timeout(time(reindexRequest.getTimeout())) //
|
builder.timeout(time(reindexRequest.getTimeout())) //
|
||||||
@ -1086,12 +1089,11 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
|
|
||||||
uqb.script(sb -> {
|
uqb.script(sb -> {
|
||||||
sb.lang(query.getLang()).params(params);
|
sb.lang(query.getLang()).params(params);
|
||||||
|
if (query.getScript() != null){
|
||||||
if (query.getScriptType() == ScriptType.INLINE) {
|
sb.source(s -> s.scriptString(query.getScript()));
|
||||||
sb.source(query.getScript()); //
|
|
||||||
} else if (query.getScriptType() == ScriptType.STORED) {
|
|
||||||
sb.id(query.getScript());
|
|
||||||
}
|
}
|
||||||
|
sb.id(query.getId());
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1254,11 +1256,11 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
mtrb.searchTemplates(stb -> stb
|
mtrb.searchTemplates(stb -> stb
|
||||||
.header(msearchHeaderBuilder(query, param.index(), routing))
|
.header(msearchHeaderBuilder(query, param.index(), routing))
|
||||||
.body(bb -> {
|
.body(bb -> {
|
||||||
bb //
|
bb.explain(query.getExplain()) //
|
||||||
.explain(query.getExplain()) //
|
.id(query.getId()); //
|
||||||
.id(query.getId()) //
|
if (query.getSource() != null){
|
||||||
.source(query.getSource()) //
|
bb.source(s -> s.scriptString(query.getSource()));
|
||||||
;
|
}
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(query.getParams())) {
|
if (!CollectionUtils.isEmpty(query.getParams())) {
|
||||||
Map<String, JsonData> params = getTemplateParams(query.getParams().entrySet());
|
Map<String, JsonData> params = getTemplateParams(query.getParams().entrySet());
|
||||||
@ -1349,7 +1351,9 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
|
|
||||||
if (script != null) {
|
if (script != null) {
|
||||||
rfb.script(s -> {
|
rfb.script(s -> {
|
||||||
s.source(script);
|
if (script != null) {
|
||||||
|
s.source(so -> so.scriptString(script));
|
||||||
|
}
|
||||||
|
|
||||||
if (runtimeField.getParams() != null) {
|
if (runtimeField.getParams() != null) {
|
||||||
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
|
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
|
||||||
@ -1551,7 +1555,9 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
String script = runtimeField.getScript();
|
String script = runtimeField.getScript();
|
||||||
if (script != null) {
|
if (script != null) {
|
||||||
rfb.script(s -> {
|
rfb.script(s -> {
|
||||||
s.source(script);
|
if (script != null) {
|
||||||
|
s.source(so -> so.scriptString(script));
|
||||||
|
}
|
||||||
|
|
||||||
if (runtimeField.getParams() != null) {
|
if (runtimeField.getParams() != null) {
|
||||||
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
|
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
|
||||||
@ -1648,7 +1654,7 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
builder.highlight(highlight);
|
builder.highlight(highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHighlight(Query query, MultisearchBody.Builder builder) {
|
private void addHighlight(Query query, SearchRequestBody.Builder builder) {
|
||||||
|
|
||||||
Highlight highlight = query.getHighlightQuery()
|
Highlight highlight = query.getHighlightQuery()
|
||||||
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext(), this)
|
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext(), this)
|
||||||
@ -1772,7 +1778,7 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
private void prepareNativeSearch(NativeQuery query, MultisearchBody.Builder builder) {
|
private void prepareNativeSearch(NativeQuery query, SearchRequestBody.Builder builder) {
|
||||||
|
|
||||||
builder //
|
builder //
|
||||||
.suggest(query.getSuggester()) //
|
.suggest(query.getSuggester()) //
|
||||||
@ -1891,10 +1897,11 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
.id(query.getId()) //
|
.id(query.getId()) //
|
||||||
.index(Arrays.asList(index.getIndexNames())) //
|
.index(Arrays.asList(index.getIndexNames())) //
|
||||||
.preference(query.getPreference()) //
|
.preference(query.getPreference()) //
|
||||||
.searchType(searchType(query.getSearchType())) //
|
.searchType(searchType(query.getSearchType())); //
|
||||||
.source(query.getSource()) //
|
|
||||||
;
|
|
||||||
|
|
||||||
|
if (query.getSource() != null) {
|
||||||
|
builder.source(so -> so.scriptString(query.getSource()));
|
||||||
|
}
|
||||||
if (query.getRoute() != null) {
|
if (query.getRoute() != null) {
|
||||||
builder.routing(query.getRoute());
|
builder.routing(query.getRoute());
|
||||||
} else if (StringUtils.hasText(routing)) {
|
} else if (StringUtils.hasText(routing)) {
|
||||||
@ -1936,8 +1943,8 @@ class RequestConverter extends AbstractQueryProcessor {
|
|||||||
return PutScriptRequest.of(b -> b //
|
return PutScriptRequest.of(b -> b //
|
||||||
.id(script.id()) //
|
.id(script.id()) //
|
||||||
.script(sb -> sb //
|
.script(sb -> sb //
|
||||||
.lang(script.language()) //
|
.lang(script.language()) //
|
||||||
.source(script.source())));
|
.source(s -> s.scriptString(script.source()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetScriptRequest scriptGet(String name) {
|
public GetScriptRequest scriptGet(String name) {
|
||||||
|
@ -191,7 +191,7 @@ class ResponseConverter {
|
|||||||
Assert.notNull(getMappingResponse, "getMappingResponse must not be null");
|
Assert.notNull(getMappingResponse, "getMappingResponse must not be null");
|
||||||
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
|
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
|
||||||
|
|
||||||
Map<String, IndexMappingRecord> mappings = getMappingResponse.result();
|
Map<String, IndexMappingRecord> mappings = getMappingResponse.mappings();
|
||||||
|
|
||||||
if (mappings == null || mappings.isEmpty()) {
|
if (mappings == null || mappings.isEmpty()) {
|
||||||
return Document.create();
|
return Document.create();
|
||||||
@ -219,7 +219,7 @@ class ResponseConverter {
|
|||||||
|
|
||||||
List<IndexInformation> indexInformationList = new ArrayList<>();
|
List<IndexInformation> indexInformationList = new ArrayList<>();
|
||||||
|
|
||||||
getIndexResponse.result().forEach((indexName, indexState) -> {
|
getIndexResponse.indices().forEach((indexName, indexState) -> {
|
||||||
Settings settings = indexState.settings() != null ? Settings.parse(toJson(indexState.settings(), jsonpMapper))
|
Settings settings = indexState.settings() != null ? Settings.parse(toJson(indexState.settings(), jsonpMapper))
|
||||||
: new Settings();
|
: new Settings();
|
||||||
Document mappings = indexState.mappings() != null ? Document.parse(toJson(indexState.mappings(), jsonpMapper))
|
Document mappings = indexState.mappings() != null ? Document.parse(toJson(indexState.mappings(), jsonpMapper))
|
||||||
@ -239,7 +239,7 @@ class ResponseConverter {
|
|||||||
Assert.notNull(getAliasResponse, "getAliasResponse must not be null");
|
Assert.notNull(getAliasResponse, "getAliasResponse must not be null");
|
||||||
|
|
||||||
Map<String, Set<AliasData>> aliasDataMap = new HashMap<>();
|
Map<String, Set<AliasData>> aliasDataMap = new HashMap<>();
|
||||||
getAliasResponse.result().forEach((indexName, alias) -> {
|
getAliasResponse.aliases().forEach((indexName, alias) -> {
|
||||||
Set<AliasData> aliasDataSet = new HashSet<>();
|
Set<AliasData> aliasDataSet = new HashSet<>();
|
||||||
alias.aliases()
|
alias.aliases()
|
||||||
.forEach((aliasName, aliasDefinition) -> aliasDataSet.add(indicesGetAliasData(aliasName, aliasDefinition)));
|
.forEach((aliasName, aliasDefinition) -> aliasDataSet.add(indicesGetAliasData(aliasName, aliasDefinition)));
|
||||||
@ -535,7 +535,7 @@ class ResponseConverter {
|
|||||||
? Script.builder() //
|
? Script.builder() //
|
||||||
.withId(response.id()) //
|
.withId(response.id()) //
|
||||||
.withLanguage(response.script().lang()) //
|
.withLanguage(response.script().lang()) //
|
||||||
.withSource(response.script().source()).build() //
|
.withSource(response.script().source().scriptString()).build() //
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
@ -48,12 +48,12 @@ public class SearchHit<T> {
|
|||||||
@Nullable private final NestedMetaData nestedMetaData;
|
@Nullable private final NestedMetaData nestedMetaData;
|
||||||
@Nullable private final String routing;
|
@Nullable private final String routing;
|
||||||
@Nullable private final Explanation explanation;
|
@Nullable private final Explanation explanation;
|
||||||
private final List<String> matchedQueries = new ArrayList<>();
|
private final Map<String, Double> matchedQueries = new LinkedHashMap<>();
|
||||||
|
|
||||||
public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score,
|
public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score,
|
||||||
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields,
|
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields,
|
||||||
@Nullable Map<String, SearchHits<?>> innerHits, @Nullable NestedMetaData nestedMetaData,
|
@Nullable Map<String, SearchHits<?>> innerHits, @Nullable NestedMetaData nestedMetaData,
|
||||||
@Nullable Explanation explanation, @Nullable List<String> matchedQueries, T content) {
|
@Nullable Explanation explanation, @Nullable Map<String, Double> matchedQueries, T content) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.routing = routing;
|
this.routing = routing;
|
||||||
@ -73,7 +73,7 @@ public class SearchHit<T> {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
if (matchedQueries != null) {
|
if (matchedQueries != null) {
|
||||||
this.matchedQueries.addAll(matchedQueries);
|
this.matchedQueries.putAll(matchedQueries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ public class SearchHit<T> {
|
|||||||
* @return the matched queries for this SearchHit.
|
* @return the matched queries for this SearchHit.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public List<String> getMatchedQueries() {
|
public Map<String, Double> getMatchedQueries() {
|
||||||
return matchedQueries;
|
return matchedQueries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,5 +125,5 @@ public interface SearchDocument extends Document {
|
|||||||
* @return the matched queries for the SearchHit.
|
* @return the matched queries for the SearchHit.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
List<String> getMatchedQueries();
|
Map<String, Double> getMatchedQueries();
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ public class SearchDocumentAdapter implements SearchDocument {
|
|||||||
private final Map<String, SearchDocumentResponse> innerHits = new HashMap<>();
|
private final Map<String, SearchDocumentResponse> innerHits = new HashMap<>();
|
||||||
@Nullable private final NestedMetaData nestedMetaData;
|
@Nullable private final NestedMetaData nestedMetaData;
|
||||||
@Nullable private final Explanation explanation;
|
@Nullable private final Explanation explanation;
|
||||||
@Nullable private final List<String> matchedQueries;
|
@Nullable private final Map<String, Double> matchedQueries;
|
||||||
@Nullable private final String routing;
|
@Nullable private final String routing;
|
||||||
|
|
||||||
public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map<String, List<Object>> fields,
|
public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map<String, List<Object>> fields,
|
||||||
Map<String, List<String>> highlightFields, Map<String, SearchDocumentResponse> innerHits,
|
Map<String, List<String>> highlightFields, Map<String, SearchDocumentResponse> innerHits,
|
||||||
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable List<String> matchedQueries,
|
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable Map<String, Double> matchedQueries,
|
||||||
@Nullable String routing) {
|
@Nullable String routing) {
|
||||||
|
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
@ -249,7 +249,7 @@ public class SearchDocumentAdapter implements SearchDocument {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public List<String> getMatchedQueries() {
|
public Map<String, Double> getMatchedQueries() {
|
||||||
return matchedQueries;
|
return matchedQueries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,15 +27,12 @@ import org.springframework.util.Assert;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
public record ScriptData(ScriptType type, @Nullable String language, @Nullable String script,
|
public record ScriptData(@Nullable String language, @Nullable String script,
|
||||||
@Nullable String scriptName, @Nullable Map<String, Object> params) {
|
@Nullable String scriptName, @Nullable Map<String, Object> params) {
|
||||||
|
|
||||||
public ScriptData(ScriptType type, @Nullable String language, @Nullable String script, @Nullable String scriptName,
|
public ScriptData(@Nullable String language, @Nullable String script, @Nullable String scriptName,
|
||||||
@Nullable Map<String, Object> params) {
|
@Nullable Map<String, Object> params) {
|
||||||
|
|
||||||
Assert.notNull(type, "type must not be null");
|
|
||||||
|
|
||||||
this.type = type;
|
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.script = script;
|
this.script = script;
|
||||||
this.scriptName = scriptName;
|
this.scriptName = scriptName;
|
||||||
@ -45,9 +42,9 @@ public record ScriptData(ScriptType type, @Nullable String language, @Nullable S
|
|||||||
/**
|
/**
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public static ScriptData of(ScriptType type, @Nullable String language, @Nullable String script,
|
public static ScriptData of(@Nullable String language, @Nullable String script,
|
||||||
@Nullable String scriptName, @Nullable Map<String, Object> params) {
|
@Nullable String scriptName, @Nullable Map<String, Object> params) {
|
||||||
return new ScriptData(type, language, script, scriptName, params);
|
return new ScriptData(language, script, scriptName, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScriptData of(Function<Builder, Builder> builderFunction) {
|
public static ScriptData of(Function<Builder, Builder> builderFunction) {
|
||||||
@ -68,7 +65,6 @@ public record ScriptData(ScriptType type, @Nullable String language, @Nullable S
|
|||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
@Nullable private ScriptType type;
|
|
||||||
@Nullable private String language;
|
@Nullable private String language;
|
||||||
@Nullable private String script;
|
@Nullable private String script;
|
||||||
@Nullable private String scriptName;
|
@Nullable private String scriptName;
|
||||||
@ -76,14 +72,6 @@ public record ScriptData(ScriptType type, @Nullable String language, @Nullable S
|
|||||||
|
|
||||||
private Builder() {}
|
private Builder() {}
|
||||||
|
|
||||||
public Builder withType(ScriptType type) {
|
|
||||||
|
|
||||||
Assert.notNull(type, "type must not be null");
|
|
||||||
|
|
||||||
this.type = type;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withLanguage(@Nullable String language) {
|
public Builder withLanguage(@Nullable String language) {
|
||||||
this.language = language;
|
this.language = language;
|
||||||
return this;
|
return this;
|
||||||
@ -106,9 +94,7 @@ public record ScriptData(ScriptType type, @Nullable String language, @Nullable S
|
|||||||
|
|
||||||
public ScriptData build() {
|
public ScriptData build() {
|
||||||
|
|
||||||
Assert.notNull(type, "type must be set");
|
return new ScriptData(language, script, scriptName, params);
|
||||||
|
|
||||||
return new ScriptData(type, language, script, scriptName, params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2021-2025 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.elasticsearch.core.query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define script types for update queries.
|
|
||||||
*
|
|
||||||
* @author Farid Faoudi
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
|
|
||||||
public enum ScriptType {
|
|
||||||
INLINE, STORED
|
|
||||||
}
|
|
@ -76,7 +76,7 @@ public class UpdateQuery {
|
|||||||
@Nullable String timeout, @Nullable String waitForActiveShards, @Nullable Query query,
|
@Nullable String timeout, @Nullable String waitForActiveShards, @Nullable Query query,
|
||||||
@Nullable Boolean abortOnVersionConflict, @Nullable Integer batchSize, @Nullable Integer maxDocs,
|
@Nullable Boolean abortOnVersionConflict, @Nullable Integer batchSize, @Nullable Integer maxDocs,
|
||||||
@Nullable Integer maxRetries, @Nullable String pipeline, @Nullable Float requestsPerSecond,
|
@Nullable Integer maxRetries, @Nullable String pipeline, @Nullable Float requestsPerSecond,
|
||||||
@Nullable Boolean shouldStoreResult, @Nullable Integer slices, @Nullable ScriptType scriptType,
|
@Nullable Boolean shouldStoreResult, @Nullable Integer slices,
|
||||||
@Nullable String scriptName, @Nullable String indexName) {
|
@Nullable String scriptName, @Nullable String indexName) {
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -105,8 +105,8 @@ public class UpdateQuery {
|
|||||||
this.slices = slices;
|
this.slices = slices;
|
||||||
this.indexName = indexName;
|
this.indexName = indexName;
|
||||||
|
|
||||||
if (scriptType != null || lang != null || script != null || scriptName != null || params != null) {
|
if (lang != null || script != null || scriptName != null || params != null) {
|
||||||
this.scriptData = new ScriptData(scriptType, lang, script, scriptName, params);
|
this.scriptData = new ScriptData(lang, script, scriptName, params);
|
||||||
} else {
|
} else {
|
||||||
this.scriptData = null;
|
this.scriptData = null;
|
||||||
}
|
}
|
||||||
@ -246,11 +246,6 @@ public class UpdateQuery {
|
|||||||
return slices;
|
return slices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public ScriptType getScriptType() {
|
|
||||||
return scriptData != null ? scriptData.type() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getScriptName() {
|
public String getScriptName() {
|
||||||
return scriptData != null ? scriptData.scriptName() : null;
|
return scriptData != null ? scriptData.scriptName() : null;
|
||||||
@ -300,7 +295,6 @@ public class UpdateQuery {
|
|||||||
@Nullable private Float requestsPerSecond;
|
@Nullable private Float requestsPerSecond;
|
||||||
@Nullable private Boolean shouldStoreResult;
|
@Nullable private Boolean shouldStoreResult;
|
||||||
@Nullable private Integer slices;
|
@Nullable private Integer slices;
|
||||||
@Nullable private ScriptType scriptType;
|
|
||||||
@Nullable private String scriptName;
|
@Nullable private String scriptName;
|
||||||
@Nullable private String indexName;
|
@Nullable private String indexName;
|
||||||
|
|
||||||
@ -437,11 +431,6 @@ public class UpdateQuery {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withScriptType(ScriptType scriptType) {
|
|
||||||
this.scriptType = scriptType;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withScriptName(String scriptName) {
|
public Builder withScriptName(String scriptName) {
|
||||||
this.scriptName = scriptName;
|
this.scriptName = scriptName;
|
||||||
return this;
|
return this;
|
||||||
@ -456,7 +445,7 @@ public class UpdateQuery {
|
|||||||
return new UpdateQuery(id, script, params, document, upsert, lang, routing, scriptedUpsert, docAsUpsert,
|
return new UpdateQuery(id, script, params, document, upsert, lang, routing, scriptedUpsert, docAsUpsert,
|
||||||
fetchSource, fetchSourceIncludes, fetchSourceExcludes, ifSeqNo, ifPrimaryTerm, refreshPolicy, retryOnConflict,
|
fetchSource, fetchSourceIncludes, fetchSourceExcludes, ifSeqNo, ifPrimaryTerm, refreshPolicy, retryOnConflict,
|
||||||
timeout, waitForActiveShards, query, abortOnVersionConflict, batchSize, maxDocs, maxRetries, pipeline,
|
timeout, waitForActiveShards, query, abortOnVersionConflict, batchSize, maxDocs, maxRetries, pipeline,
|
||||||
requestsPerSecond, shouldStoreResult, slices, scriptType, scriptName, indexName);
|
requestsPerSecond, shouldStoreResult, slices, scriptName, indexName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withIndex(@Nullable String indexName) {
|
public Builder withIndex(@Nullable String indexName) {
|
||||||
|
@ -249,16 +249,15 @@ public class ReindexRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Script {
|
public static class Script {
|
||||||
private final String source;
|
@Nullable private final String source;
|
||||||
@Nullable private final String lang;
|
@Nullable private final String lang;
|
||||||
|
|
||||||
private Script(String source, @Nullable String lang) {
|
private Script(@Nullable String source, @Nullable String lang) {
|
||||||
Assert.notNull(source, "source must not be null");
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.lang = lang;
|
this.lang = lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ public record Script(String id, String language, String source) {
|
|||||||
|
|
||||||
Assert.notNull(id, "id must not be null");
|
Assert.notNull(id, "id must not be null");
|
||||||
Assert.notNull(language, "language must not be null");
|
Assert.notNull(language, "language must not be null");
|
||||||
Assert.notNull(source, "source must not be null");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ScriptBuilder builder() {
|
public static ScriptBuilder builder() {
|
||||||
@ -62,8 +60,6 @@ public record Script(String id, String language, String source) {
|
|||||||
|
|
||||||
public ScriptBuilder withSource(String source) {
|
public ScriptBuilder withSource(String source) {
|
||||||
|
|
||||||
Assert.notNull(source, "source must not be null");
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.assertj.core.api.SoftAssertions;
|
import org.assertj.core.api.SoftAssertions;
|
||||||
import org.assertj.core.data.Offset;
|
import org.assertj.core.data.Offset;
|
||||||
@ -144,17 +145,17 @@ class DocumentAdaptersUnitTests {
|
|||||||
Hit<EntityAsMap> searchHit = new Hit.Builder<EntityAsMap>() //
|
Hit<EntityAsMap> searchHit = new Hit.Builder<EntityAsMap>() //
|
||||||
.index("index") //
|
.index("index") //
|
||||||
.id("42") //
|
.id("42") //
|
||||||
.matchedQueries("query1", "query2") //
|
.matchedQueries("query1", 1D) //
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
SearchDocument searchDocument = DocumentAdapters.from(searchHit, jsonpMapper);
|
SearchDocument searchDocument = DocumentAdapters.from(searchHit, jsonpMapper);
|
||||||
|
|
||||||
SoftAssertions softly = new SoftAssertions();
|
SoftAssertions softly = new SoftAssertions();
|
||||||
|
|
||||||
List<String> matchedQueries = searchDocument.getMatchedQueries();
|
Map<String, Double> matchedQueries = searchDocument.getMatchedQueries();
|
||||||
softly.assertThat(matchedQueries).isNotNull();
|
softly.assertThat(matchedQueries).isNotNull();
|
||||||
softly.assertThat(matchedQueries).hasSize(2);
|
softly.assertThat(matchedQueries).hasSize(1);
|
||||||
softly.assertThat(matchedQueries).isEqualTo(Arrays.asList("query1", "query2"));
|
softly.assertThat(matchedQueries).isEqualTo(Map.of("query1",1D));
|
||||||
softly.assertAll();
|
softly.assertAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
|||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
|
import org.springframework.data.elasticsearch.core.query.RescorerQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptType;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptedField;
|
import org.springframework.data.elasticsearch.core.query.ScriptedField;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||||
@ -183,7 +182,7 @@ public class ElasticsearchELCIntegrationTests extends ElasticsearchIntegrationTe
|
|||||||
|
|
||||||
return nativeQueryBuilder.withScriptedField(new ScriptedField( //
|
return nativeQueryBuilder.withScriptedField(new ScriptedField( //
|
||||||
fieldName, //
|
fieldName, //
|
||||||
new ScriptData(ScriptType.INLINE, "expression", script, null, params))) //
|
new ScriptData( "expression", script, null, params))) //
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1630,7 +1630,6 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
final Query query = operations.matchAllQuery();
|
final Query query = operations.matchAllQuery();
|
||||||
|
|
||||||
final UpdateQuery updateQuery = UpdateQuery.builder(query)
|
final UpdateQuery updateQuery = UpdateQuery.builder(query)
|
||||||
.withScriptType(ScriptType.INLINE)
|
|
||||||
.withScript("ctx._source['message'] = params['newMessage']").withLang("painless")
|
.withScript("ctx._source['message'] = params['newMessage']").withLang("painless")
|
||||||
.withParams(Collections.singletonMap("newMessage", messageAfterUpdate)).withAbortOnVersionConflict(true)
|
.withParams(Collections.singletonMap("newMessage", messageAfterUpdate)).withAbortOnVersionConflict(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -48,7 +48,6 @@ import org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilde
|
|||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.RuntimeField;
|
import org.springframework.data.elasticsearch.core.query.RuntimeField;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptType;
|
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||||
@ -165,7 +164,6 @@ public abstract class ReactiveScriptedAndRuntimeFieldsIntegrationTests {
|
|||||||
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
|
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
|
||||||
fieldName,
|
fieldName,
|
||||||
ScriptData.of(b -> b
|
ScriptData.of(b -> b
|
||||||
.withType(ScriptType.INLINE)
|
|
||||||
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
|
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
|
||||||
.withParams(Map.of("factor", factor))));
|
.withParams(Map.of("factor", factor))));
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ import org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilde
|
|||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.RuntimeField;
|
import org.springframework.data.elasticsearch.core.query.RuntimeField;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
import org.springframework.data.elasticsearch.core.query.ScriptData;
|
||||||
import org.springframework.data.elasticsearch.core.query.ScriptType;
|
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||||
@ -314,7 +313,6 @@ public abstract class ScriptedAndRuntimeFieldsIntegrationTests {
|
|||||||
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
|
return org.springframework.data.elasticsearch.core.query.ScriptedField.of(
|
||||||
fieldName,
|
fieldName,
|
||||||
ScriptData.of(b -> b
|
ScriptData.of(b -> b
|
||||||
.withType(ScriptType.INLINE)
|
|
||||||
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
|
.withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0")
|
||||||
.withParams(Map.of("factor", factor))));
|
.withParams(Map.of("factor", factor))));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
sde.testcontainers.image-name=docker.elastic.co/elasticsearch/elasticsearch
|
sde.testcontainers.image-name=docker.elastic.co/elasticsearch/elasticsearch
|
||||||
sde.testcontainers.image-version=8.18.1
|
sde.testcontainers.image-version=9.0.1
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# needed as we do a DELETE /* at the end of the tests, will be required from 8.0 on, produces a warning since 7.13
|
# needed as we do a DELETE /* at the end of the tests, will be required from 8.0 on, produces a warning since 7.13
|
||||||
|
Loading…
x
Reference in New Issue
Block a user