diff --git a/pom.xml b/pom.xml index 5a5bbef47..4396ce5a6 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.0.0-SNAPSHOT - 8.18.1 + 9.0.1 0.19.0 2.23.1 diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java index ccb937bf7..ea38dfe58 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java @@ -83,7 +83,7 @@ public static SearchDocument from(Hit hit, JsonpMapper jsonpMapper) { Explanation explanation = from(hit.explanation()); - List matchedQueries = hit.matchedQueries(); + Map matchedQueries = hit.matchedQueries(); Function, EntityAsMap> fromFields = fields -> { StringBuilder sb = new StringBuilder("{"); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchIndicesClient.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchIndicesClient.java index e5f6df392..3ebde9776 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchIndicesClient.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchIndicesClient.java @@ -539,14 +539,6 @@ public Mono stats() { return stats(builder -> builder); } - public Mono unfreeze(UnfreezeRequest request) { - return Mono.fromFuture(transport.performRequestAsync(request, UnfreezeRequest._ENDPOINT, transportOptions)); - } - - public Mono unfreeze(Function> fn) { - return unfreeze(fn.apply(new UnfreezeRequest.Builder()).build()); - } - public Mono updateAliases(UpdateAliasesRequest request) { return Mono.fromFuture(transport.performRequestAsync(request, UpdateAliasesRequest._ENDPOINT, transportOptions)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java index a8d8beabe..e1a6c0927 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java @@ -42,10 +42,10 @@ import co.elastic.clients.elasticsearch.core.bulk.IndexOperation; import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation; 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.search.Highlight; 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.indices.*; import co.elastic.clients.elasticsearch.indices.ExistsIndexTemplateRequest; @@ -751,11 +751,10 @@ private CreateOperation bulkCreateOperation(IndexQuery query, IndexCoordinate } return co.elastic.clients.elasticsearch._types.Script.of(sb -> { sb.lang(scriptData.language()) - .params(params); - if (scriptData.type() == ScriptType.INLINE) { - sb.source(scriptData.script()); - } else if (scriptData.type() == ScriptType.STORED) { - sb.id(scriptData.script()); + .params(params) + .id(scriptData.scriptName()); + if (scriptData.script() != null){ + sb.source(s -> s.scriptString(scriptData.script())); } return sb; }); @@ -927,9 +926,13 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque ReindexRequest.Script script = reindexRequest.getScript(); if (script != null) { - builder.script(sb -> sb - .lang(script.getLang()) - .source(script.getSource())); + builder.script(sb -> { + if (script.getSource() != null){ + sb.source(s -> s.scriptString(script.getSource())); + } + sb.lang(script.getLang()); + return sb; + }); } builder.timeout(time(reindexRequest.getTimeout())) // @@ -1086,12 +1089,11 @@ public DeleteByQueryRequest documentDeleteByQueryRequest(DeleteQuery query, @Nul uqb.script(sb -> { sb.lang(query.getLang()).params(params); - - if (query.getScriptType() == ScriptType.INLINE) { - sb.source(query.getScript()); // - } else if (query.getScriptType() == ScriptType.STORED) { - sb.id(query.getScript()); + if (query.getScript() != null){ + sb.source(s -> s.scriptString(query.getScript())); } + sb.id(query.getId()); + return sb; }); } @@ -1254,11 +1256,11 @@ public MsearchTemplateRequest searchMsearchTemplateRequest( mtrb.searchTemplates(stb -> stb .header(msearchHeaderBuilder(query, param.index(), routing)) .body(bb -> { - bb // - .explain(query.getExplain()) // - .id(query.getId()) // - .source(query.getSource()) // - ; + bb.explain(query.getExplain()) // + .id(query.getId()); // + if (query.getSource() != null){ + bb.source(s -> s.scriptString(query.getSource())); + } if (!CollectionUtils.isEmpty(query.getParams())) { Map params = getTemplateParams(query.getParams().entrySet()); @@ -1349,7 +1351,9 @@ public MsearchRequest searchMsearchRequest( if (script != null) { rfb.script(s -> { - s.source(script); + if (script != null) { + s.source(so -> so.scriptString(script)); + } if (runtimeField.getParams() != null) { s.params(TypeUtils.paramsMap(runtimeField.getParams())); @@ -1551,7 +1555,9 @@ private void prepareSearchRequest(Query query, @Nullable String routing, @Nu String script = runtimeField.getScript(); if (script != null) { rfb.script(s -> { - s.source(script); + if (script != null) { + s.source(so -> so.scriptString(script)); + } if (runtimeField.getParams() != null) { s.params(TypeUtils.paramsMap(runtimeField.getParams())); @@ -1648,7 +1654,7 @@ private void addHighlight(Query query, SearchRequest.Builder builder) { builder.highlight(highlight); } - private void addHighlight(Query query, MultisearchBody.Builder builder) { + private void addHighlight(Query query, SearchRequestBody.Builder builder) { Highlight highlight = query.getHighlightQuery() .map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext(), this) @@ -1772,7 +1778,7 @@ private void prepareNativeSearch(NativeQuery query, SearchRequest.Builder builde } @SuppressWarnings("DuplicatedCode") - private void prepareNativeSearch(NativeQuery query, MultisearchBody.Builder builder) { + private void prepareNativeSearch(NativeQuery query, SearchRequestBody.Builder builder) { builder // .suggest(query.getSuggester()) // @@ -1891,10 +1897,11 @@ public SearchTemplateRequest searchTemplate(SearchTemplateQuery query, @Nullable .id(query.getId()) // .index(Arrays.asList(index.getIndexNames())) // .preference(query.getPreference()) // - .searchType(searchType(query.getSearchType())) // - .source(query.getSource()) // - ; + .searchType(searchType(query.getSearchType())); // + if (query.getSource() != null) { + builder.source(so -> so.scriptString(query.getSource())); + } if (query.getRoute() != null) { builder.routing(query.getRoute()); } else if (StringUtils.hasText(routing)) { @@ -1936,8 +1943,8 @@ public PutScriptRequest scriptPut(Script script) { return PutScriptRequest.of(b -> b // .id(script.id()) // .script(sb -> sb // - .lang(script.language()) // - .source(script.source()))); + .lang(script.language()) // + .source(s -> s.scriptString(script.source())))); } public GetScriptRequest scriptGet(String name) { diff --git a/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java b/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java index 7024584f3..771b1104a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java @@ -191,7 +191,7 @@ public Document indicesGetMapping(GetMappingResponse getMappingResponse, IndexCo Assert.notNull(getMappingResponse, "getMappingResponse must not be null"); Assert.notNull(indexCoordinates, "indexCoordinates must not be null"); - Map mappings = getMappingResponse.result(); + Map mappings = getMappingResponse.mappings(); if (mappings == null || mappings.isEmpty()) { return Document.create(); @@ -219,7 +219,7 @@ public List indicesGetIndexInformations(GetIndexResponse getIn List indexInformationList = new ArrayList<>(); - getIndexResponse.result().forEach((indexName, indexState) -> { + getIndexResponse.indices().forEach((indexName, indexState) -> { Settings settings = indexState.settings() != null ? Settings.parse(toJson(indexState.settings(), jsonpMapper)) : new Settings(); Document mappings = indexState.mappings() != null ? Document.parse(toJson(indexState.mappings(), jsonpMapper)) @@ -239,7 +239,7 @@ public Map> indicesGetAliasData(GetAliasResponse getAlias Assert.notNull(getAliasResponse, "getAliasResponse must not be null"); Map> aliasDataMap = new HashMap<>(); - getAliasResponse.result().forEach((indexName, alias) -> { + getAliasResponse.aliases().forEach((indexName, alias) -> { Set aliasDataSet = new HashSet<>(); alias.aliases() .forEach((aliasName, aliasDefinition) -> aliasDataSet.add(indicesGetAliasData(aliasName, aliasDefinition))); @@ -535,7 +535,7 @@ public Script scriptResponse(GetScriptResponse response) { ? Script.builder() // .withId(response.id()) // .withLanguage(response.script().lang()) // - .withSource(response.script().source()).build() // + .withSource(response.script().source().scriptString()).build() // : null; } // endregion diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java index da59efdf5..6a6f21920 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java @@ -48,12 +48,12 @@ public class SearchHit { @Nullable private final NestedMetaData nestedMetaData; @Nullable private final String routing; @Nullable private final Explanation explanation; - private final List matchedQueries = new ArrayList<>(); + private final Map matchedQueries = new LinkedHashMap<>(); public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score, @Nullable Object[] sortValues, @Nullable Map> highlightFields, @Nullable Map> innerHits, @Nullable NestedMetaData nestedMetaData, - @Nullable Explanation explanation, @Nullable List matchedQueries, T content) { + @Nullable Explanation explanation, @Nullable Map matchedQueries, T content) { this.index = index; this.id = id; this.routing = routing; @@ -73,7 +73,7 @@ public SearchHit(@Nullable String index, @Nullable String id, @Nullable String r this.content = content; if (matchedQueries != null) { - this.matchedQueries.addAll(matchedQueries); + this.matchedQueries.putAll(matchedQueries); } } @@ -194,7 +194,7 @@ public Explanation getExplanation() { * @return the matched queries for this SearchHit. */ @Nullable - public List getMatchedQueries() { + public Map getMatchedQueries() { return matchedQueries; } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java index 63192272e..b51c028e7 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java @@ -125,5 +125,5 @@ default String getRouting() { * @return the matched queries for the SearchHit. */ @Nullable - List getMatchedQueries(); + Map getMatchedQueries(); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java index de424c719..4a1bf2f35 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java @@ -41,12 +41,12 @@ public class SearchDocumentAdapter implements SearchDocument { private final Map innerHits = new HashMap<>(); @Nullable private final NestedMetaData nestedMetaData; @Nullable private final Explanation explanation; - @Nullable private final List matchedQueries; + @Nullable private final Map matchedQueries; @Nullable private final String routing; public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map> fields, Map> highlightFields, Map innerHits, - @Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable List matchedQueries, + @Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable Map matchedQueries, @Nullable String routing) { this.delegate = delegate; @@ -249,7 +249,7 @@ public Explanation getExplanation() { @Override @Nullable - public List getMatchedQueries() { + public Map getMatchedQueries() { return matchedQueries; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java index 1a81988cd..1597f064f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java @@ -27,15 +27,12 @@ * @author Peter-Josef Meisch * @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 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 params) { - Assert.notNull(type, "type must not be null"); - - this.type = type; this.language = language; this.script = script; this.scriptName = scriptName; @@ -45,9 +42,9 @@ public ScriptData(ScriptType type, @Nullable String language, @Nullable String s /** * @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 params) { - return new ScriptData(type, language, script, scriptName, params); + return new ScriptData(language, script, scriptName, params); } public static ScriptData of(Function builderFunction) { @@ -68,7 +65,6 @@ public static Builder builder() { * @since 5.2 */ public static final class Builder { - @Nullable private ScriptType type; @Nullable private String language; @Nullable private String script; @Nullable private String scriptName; @@ -76,14 +72,6 @@ public static final class 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) { this.language = language; return this; @@ -106,9 +94,7 @@ public Builder withParams(@Nullable Map params) { public ScriptData build() { - Assert.notNull(type, "type must be set"); - - return new ScriptData(type, language, script, scriptName, params); + return new ScriptData(language, script, scriptName, params); } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java b/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java deleted file mode 100644 index 1c6ceecab..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java +++ /dev/null @@ -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 -} diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java b/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java index 087f0c105..75959bb56 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/UpdateQuery.java @@ -76,7 +76,7 @@ private UpdateQuery(String id, @Nullable String script, @Nullable Map searchHit = new Hit.Builder() // .index("index") // .id("42") // - .matchedQueries("query1", "query2") // + .matchedQueries("query1", 1D) // .build(); SearchDocument searchDocument = DocumentAdapters.from(searchHit, jsonpMapper); SoftAssertions softly = new SoftAssertions(); - List matchedQueries = searchDocument.getMatchedQueries(); + Map matchedQueries = searchDocument.getMatchedQueries(); softly.assertThat(matchedQueries).isNotNull(); - softly.assertThat(matchedQueries).hasSize(2); - softly.assertThat(matchedQueries).isEqualTo(Arrays.asList("query1", "query2")); + softly.assertThat(matchedQueries).hasSize(1); + softly.assertThat(matchedQueries).isEqualTo(Map.of("query1",1D)); softly.assertAll(); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java index 884fde8d9..826c2e416 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchELCIntegrationTests.java @@ -46,7 +46,6 @@ import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.data.elasticsearch.core.query.RescorerQuery; 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.junit.jupiter.ElasticsearchTemplateConfiguration; import org.springframework.data.elasticsearch.utils.IndexNameProvider; @@ -183,7 +182,7 @@ protected Query getMatchAllQueryWithIncludesAndInlineExpressionScript(@Nullable return nativeQueryBuilder.withScriptedField(new ScriptedField( // fieldName, // - new ScriptData(ScriptType.INLINE, "expression", script, null, params))) // + new ScriptData( "expression", script, null, params))) // .build(); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java index 3a2e89212..195b11b3d 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchIntegrationTests.java @@ -1630,7 +1630,6 @@ void shouldDoUpdateByQueryForExistingDocument() { final Query query = operations.matchAllQuery(); final UpdateQuery updateQuery = UpdateQuery.builder(query) - .withScriptType(ScriptType.INLINE) .withScript("ctx._source['message'] = params['newMessage']").withLang("painless") .withParams(Collections.singletonMap("newMessage", messageAfterUpdate)).withAbortOnVersionConflict(true) .build(); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java index deef102e0..c17b4a8df 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ReactiveScriptedAndRuntimeFieldsIntegrationTests.java @@ -48,7 +48,6 @@ import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.data.elasticsearch.core.query.RuntimeField; 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.repository.ReactiveElasticsearchRepository; import org.springframework.data.elasticsearch.utils.IndexNameProvider; @@ -165,7 +164,6 @@ private static org.springframework.data.elasticsearch.core.query.ScriptedField g return org.springframework.data.elasticsearch.core.query.ScriptedField.of( fieldName, ScriptData.of(b -> b - .withType(ScriptType.INLINE) .withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0") .withParams(Map.of("factor", factor)))); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java index 20f29ab66..d4b147d46 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/query/scriptedandruntimefields/ScriptedAndRuntimeFieldsIntegrationTests.java @@ -45,7 +45,6 @@ import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.data.elasticsearch.core.query.RuntimeField; 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.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.utils.IndexNameProvider; @@ -314,7 +313,6 @@ private static org.springframework.data.elasticsearch.core.query.ScriptedField b return org.springframework.data.elasticsearch.core.query.ScriptedField.of( fieldName, ScriptData.of(b -> b - .withType(ScriptType.INLINE) .withScript("doc['value'].size() > 0 ? doc['value'].value * params['factor'] : 0") .withParams(Map.of("factor", factor)))); } diff --git a/src/test/resources/testcontainers-elasticsearch.properties b/src/test/resources/testcontainers-elasticsearch.properties index 6860b4150..a16e4a2af 100644 --- a/src/test/resources/testcontainers-elasticsearch.properties +++ b/src/test/resources/testcontainers-elasticsearch.properties @@ -15,7 +15,7 @@ # # 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