Skip to content

Commit add353e

Browse files
committed
es java client major update
1 parent ebbe242 commit add353e

19 files changed

+68
-131
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<springdata.commons>3.5.0-SNAPSHOT</springdata.commons>
2222

2323
<!-- version of the ElasticsearchClient -->
24-
<elasticsearch-java>8.18.1</elasticsearch-java>
24+
<elasticsearch-java>9.0.1</elasticsearch-java>
2525

2626
<hoverfly>0.19.0</hoverfly>
2727
<log4j>2.23.1</log4j>

src/main/java/org/springframework/data/elasticsearch/client/elc/DocumentAdapters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static SearchDocument from(Hit<?> hit, JsonpMapper jsonpMapper) {
8383

8484
Explanation explanation = from(hit.explanation());
8585

86-
List<String> matchedQueries = hit.matchedQueries();
86+
Map<String, Double> matchedQueries = hit.matchedQueries();
8787

8888
Function<Map<String, JsonData>, EntityAsMap> fromFields = fields -> {
8989
StringBuilder sb = new StringBuilder("{");

src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchIndicesClient.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,6 @@ public Mono<IndicesStatsResponse> stats() {
539539
return stats(builder -> builder);
540540
}
541541

542-
public Mono<UnfreezeResponse> unfreeze(UnfreezeRequest request) {
543-
return Mono.fromFuture(transport.performRequestAsync(request, UnfreezeRequest._ENDPOINT, transportOptions));
544-
}
545-
546-
public Mono<UnfreezeResponse> unfreeze(Function<UnfreezeRequest.Builder, ObjectBuilder<UnfreezeRequest>> fn) {
547-
return unfreeze(fn.apply(new UnfreezeRequest.Builder()).build());
548-
}
549-
550542
public Mono<UpdateAliasesResponse> updateAliases(UpdateAliasesRequest request) {
551543
return Mono.fromFuture(transport.performRequestAsync(request, UpdateAliasesRequest._ENDPOINT, transportOptions));
552544
}

src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
import co.elastic.clients.elasticsearch.core.bulk.IndexOperation;
4343
import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation;
4444
import co.elastic.clients.elasticsearch.core.mget.MultiGetOperation;
45-
import co.elastic.clients.elasticsearch.core.msearch.MultisearchBody;
4645
import co.elastic.clients.elasticsearch.core.msearch.MultisearchHeader;
4746
import co.elastic.clients.elasticsearch.core.search.Highlight;
4847
import co.elastic.clients.elasticsearch.core.search.Rescore;
48+
import co.elastic.clients.elasticsearch.core.search.SearchRequestBody;
4949
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
5050
import co.elastic.clients.elasticsearch.indices.*;
5151
import co.elastic.clients.elasticsearch.indices.ExistsIndexTemplateRequest;
@@ -752,11 +752,10 @@ private co.elastic.clients.elasticsearch._types.Script getScript(@Nullable Scrip
752752
}
753753
return co.elastic.clients.elasticsearch._types.Script.of(sb -> {
754754
sb.lang(scriptData.language())
755-
.params(params);
756-
if (scriptData.type() == ScriptType.INLINE) {
757-
sb.source(scriptData.script());
758-
} else if (scriptData.type() == ScriptType.STORED) {
759-
sb.id(scriptData.script());
755+
.params(params)
756+
.id(scriptData.scriptName());
757+
if (scriptData.script() != null){
758+
sb.source(s -> s.scriptString(scriptData.script()));
760759
}
761760
return sb;
762761
});
@@ -928,9 +927,13 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque
928927

929928
ReindexRequest.Script script = reindexRequest.getScript();
930929
if (script != null) {
931-
builder.script(sb -> sb
932-
.lang(script.getLang())
933-
.source(script.getSource()));
930+
builder.script(sb -> {
931+
if (script.getSource() != null){
932+
sb.source(s -> s.scriptString(script.getSource()));
933+
}
934+
sb.lang(script.getLang());
935+
return sb;
936+
});
934937
}
935938

936939
builder.timeout(time(reindexRequest.getTimeout())) //
@@ -1087,12 +1090,11 @@ public DeleteByQueryRequest documentDeleteByQueryRequest(DeleteQuery query, @Nul
10871090

10881091
uqb.script(sb -> {
10891092
sb.lang(query.getLang()).params(params);
1090-
1091-
if (query.getScriptType() == ScriptType.INLINE) {
1092-
sb.source(query.getScript()); //
1093-
} else if (query.getScriptType() == ScriptType.STORED) {
1094-
sb.id(query.getScript());
1093+
if (query.getScript() != null){
1094+
sb.source(s -> s.scriptString(query.getScript()));
10951095
}
1096+
sb.id(query.getId());
1097+
10961098
return sb;
10971099
});
10981100
}
@@ -1255,11 +1257,11 @@ public MsearchTemplateRequest searchMsearchTemplateRequest(
12551257
mtrb.searchTemplates(stb -> stb
12561258
.header(msearchHeaderBuilder(query, param.index(), routing))
12571259
.body(bb -> {
1258-
bb //
1259-
.explain(query.getExplain()) //
1260-
.id(query.getId()) //
1261-
.source(query.getSource()) //
1262-
;
1260+
bb.explain(query.getExplain()) //
1261+
.id(query.getId()); //
1262+
if (query.getSource() != null){
1263+
bb.source(s -> s.scriptString(query.getSource()));
1264+
}
12631265

12641266
if (!CollectionUtils.isEmpty(query.getParams())) {
12651267
Map<String, JsonData> params = getTemplateParams(query.getParams().entrySet());
@@ -1350,7 +1352,9 @@ public MsearchRequest searchMsearchRequest(
13501352

13511353
if (script != null) {
13521354
rfb.script(s -> {
1353-
s.source(script);
1355+
if (script != null) {
1356+
s.source(so -> so.scriptString(script));
1357+
}
13541358

13551359
if (runtimeField.getParams() != null) {
13561360
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
@@ -1552,7 +1556,9 @@ private <T> void prepareSearchRequest(Query query, @Nullable String routing, @Nu
15521556
String script = runtimeField.getScript();
15531557
if (script != null) {
15541558
rfb.script(s -> {
1555-
s.source(script);
1559+
if (script != null) {
1560+
s.source(so -> so.scriptString(script));
1561+
}
15561562

15571563
if (runtimeField.getParams() != null) {
15581564
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
@@ -1649,7 +1655,7 @@ private void addHighlight(Query query, SearchRequest.Builder builder) {
16491655
builder.highlight(highlight);
16501656
}
16511657

1652-
private void addHighlight(Query query, MultisearchBody.Builder builder) {
1658+
private void addHighlight(Query query, SearchRequestBody.Builder builder) {
16531659

16541660
Highlight highlight = query.getHighlightQuery()
16551661
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext(), this)
@@ -1773,7 +1779,7 @@ private void prepareNativeSearch(NativeQuery query, SearchRequest.Builder builde
17731779
}
17741780

17751781
@SuppressWarnings("DuplicatedCode")
1776-
private void prepareNativeSearch(NativeQuery query, MultisearchBody.Builder builder) {
1782+
private void prepareNativeSearch(NativeQuery query, SearchRequestBody.Builder builder) {
17771783

17781784
builder //
17791785
.suggest(query.getSuggester()) //
@@ -1893,10 +1899,11 @@ public SearchTemplateRequest searchTemplate(SearchTemplateQuery query, @Nullable
18931899
.id(query.getId()) //
18941900
.index(Arrays.asList(index.getIndexNames())) //
18951901
.preference(query.getPreference()) //
1896-
.searchType(searchType(query.getSearchType())) //
1897-
.source(query.getSource()) //
1898-
;
1902+
.searchType(searchType(query.getSearchType())); //
18991903

1904+
if (query.getSource() != null) {
1905+
builder.source(so -> so.scriptString(query.getSource()));
1906+
}
19001907
if (query.getRoute() != null) {
19011908
builder.routing(query.getRoute());
19021909
} else if (StringUtils.hasText(routing)) {
@@ -1938,8 +1945,8 @@ public PutScriptRequest scriptPut(Script script) {
19381945
return PutScriptRequest.of(b -> b //
19391946
.id(script.id()) //
19401947
.script(sb -> sb //
1941-
.lang(script.language()) //
1942-
.source(script.source())));
1948+
.lang(script.language()) //
1949+
.source(s -> s.scriptString(script.source()))));
19431950
}
19441951

19451952
public GetScriptRequest scriptGet(String name) {

src/main/java/org/springframework/data/elasticsearch/client/elc/ResponseConverter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public Document indicesGetMapping(GetMappingResponse getMappingResponse, IndexCo
191191
Assert.notNull(getMappingResponse, "getMappingResponse must not be null");
192192
Assert.notNull(indexCoordinates, "indexCoordinates must not be null");
193193

194-
Map<String, IndexMappingRecord> mappings = getMappingResponse.result();
194+
Map<String, IndexMappingRecord> mappings = getMappingResponse.mappings();
195195

196196
if (mappings == null || mappings.isEmpty()) {
197197
return Document.create();
@@ -219,7 +219,7 @@ public List<IndexInformation> indicesGetIndexInformations(GetIndexResponse getIn
219219

220220
List<IndexInformation> indexInformationList = new ArrayList<>();
221221

222-
getIndexResponse.result().forEach((indexName, indexState) -> {
222+
getIndexResponse.indices().forEach((indexName, indexState) -> {
223223
Settings settings = indexState.settings() != null ? Settings.parse(toJson(indexState.settings(), jsonpMapper))
224224
: new Settings();
225225
Document mappings = indexState.mappings() != null ? Document.parse(toJson(indexState.mappings(), jsonpMapper))
@@ -239,7 +239,7 @@ public Map<String, Set<AliasData>> indicesGetAliasData(GetAliasResponse getAlias
239239
Assert.notNull(getAliasResponse, "getAliasResponse must not be null");
240240

241241
Map<String, Set<AliasData>> aliasDataMap = new HashMap<>();
242-
getAliasResponse.result().forEach((indexName, alias) -> {
242+
getAliasResponse.aliases().forEach((indexName, alias) -> {
243243
Set<AliasData> aliasDataSet = new HashSet<>();
244244
alias.aliases()
245245
.forEach((aliasName, aliasDefinition) -> aliasDataSet.add(indicesGetAliasData(aliasName, aliasDefinition)));
@@ -536,7 +536,7 @@ public Script scriptResponse(GetScriptResponse response) {
536536
? Script.builder() //
537537
.withId(response.id()) //
538538
.withLanguage(response.script().lang()) //
539-
.withSource(response.script().source()).build() //
539+
.withSource(response.script().source().scriptString()).build() //
540540
: null;
541541
}
542542
// endregion

src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public class SearchHit<T> {
4848
@Nullable private final NestedMetaData nestedMetaData;
4949
@Nullable private final String routing;
5050
@Nullable private final Explanation explanation;
51-
private final List<String> matchedQueries = new ArrayList<>();
51+
private final Map<String, Double> matchedQueries = new LinkedHashMap<>();
5252

5353
public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score,
5454
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields,
5555
@Nullable Map<String, SearchHits<?>> innerHits, @Nullable NestedMetaData nestedMetaData,
56-
@Nullable Explanation explanation, @Nullable List<String> matchedQueries, T content) {
56+
@Nullable Explanation explanation, @Nullable Map<String, Double> matchedQueries, T content) {
5757
this.index = index;
5858
this.id = id;
5959
this.routing = routing;
@@ -73,7 +73,7 @@ public SearchHit(@Nullable String index, @Nullable String id, @Nullable String r
7373
this.content = content;
7474

7575
if (matchedQueries != null) {
76-
this.matchedQueries.addAll(matchedQueries);
76+
this.matchedQueries.putAll(matchedQueries);
7777
}
7878
}
7979

@@ -194,7 +194,7 @@ public Explanation getExplanation() {
194194
* @return the matched queries for this SearchHit.
195195
*/
196196
@Nullable
197-
public List<String> getMatchedQueries() {
197+
public Map<String, Double> getMatchedQueries() {
198198
return matchedQueries;
199199
}
200200
}

src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ default String getRouting() {
125125
* @return the matched queries for the SearchHit.
126126
*/
127127
@Nullable
128-
List<String> getMatchedQueries();
128+
Map<String, Double> getMatchedQueries();
129129
}

src/main/java/org/springframework/data/elasticsearch/core/document/SearchDocumentAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public class SearchDocumentAdapter implements SearchDocument {
4141
private final Map<String, SearchDocumentResponse> innerHits = new HashMap<>();
4242
@Nullable private final NestedMetaData nestedMetaData;
4343
@Nullable private final Explanation explanation;
44-
@Nullable private final List<String> matchedQueries;
44+
@Nullable private final Map<String, Double> matchedQueries;
4545
@Nullable private final String routing;
4646

4747
public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map<String, List<Object>> fields,
4848
Map<String, List<String>> highlightFields, Map<String, SearchDocumentResponse> innerHits,
49-
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable List<String> matchedQueries,
49+
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable Map<String, Double> matchedQueries,
5050
@Nullable String routing) {
5151

5252
this.delegate = delegate;
@@ -249,7 +249,7 @@ public Explanation getExplanation() {
249249

250250
@Override
251251
@Nullable
252-
public List<String> getMatchedQueries() {
252+
public Map<String, Double> getMatchedQueries() {
253253
return matchedQueries;
254254
}
255255

src/main/java/org/springframework/data/elasticsearch/core/query/ScriptData.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
* @author Peter-Josef Meisch
2828
* @since 4.4
2929
*/
30-
public record ScriptData(ScriptType type, @Nullable String language, @Nullable String script,
30+
public record ScriptData(@Nullable String language, @Nullable String script,
3131
@Nullable String scriptName, @Nullable Map<String, Object> params) {
3232

33-
public ScriptData(ScriptType type, @Nullable String language, @Nullable String script, @Nullable String scriptName,
33+
public ScriptData(@Nullable String language, @Nullable String script, @Nullable String scriptName,
3434
@Nullable Map<String, Object> params) {
3535

36-
Assert.notNull(type, "type must not be null");
37-
38-
this.type = type;
3936
this.language = language;
4037
this.script = script;
4138
this.scriptName = scriptName;
@@ -45,9 +42,9 @@ public ScriptData(ScriptType type, @Nullable String language, @Nullable String s
4542
/**
4643
* @since 5.2
4744
*/
48-
public static ScriptData of(ScriptType type, @Nullable String language, @Nullable String script,
45+
public static ScriptData of(@Nullable String language, @Nullable String script,
4946
@Nullable String scriptName, @Nullable Map<String, Object> params) {
50-
return new ScriptData(type, language, script, scriptName, params);
47+
return new ScriptData(language, script, scriptName, params);
5148
}
5249

5350
public static ScriptData of(Function<Builder, Builder> builderFunction) {
@@ -68,22 +65,13 @@ public static Builder builder() {
6865
* @since 5.2
6966
*/
7067
public static final class Builder {
71-
@Nullable private ScriptType type;
7268
@Nullable private String language;
7369
@Nullable private String script;
7470
@Nullable private String scriptName;
7571
@Nullable private Map<String, Object> params;
7672

7773
private Builder() {}
7874

79-
public Builder withType(ScriptType type) {
80-
81-
Assert.notNull(type, "type must not be null");
82-
83-
this.type = type;
84-
return this;
85-
}
86-
8775
public Builder withLanguage(@Nullable String language) {
8876
this.language = language;
8977
return this;
@@ -106,9 +94,7 @@ public Builder withParams(@Nullable Map<String, Object> params) {
10694

10795
public ScriptData build() {
10896

109-
Assert.notNull(type, "type must be set");
110-
111-
return new ScriptData(type, language, script, scriptName, params);
97+
return new ScriptData(language, script, scriptName, params);
11298
}
11399
}
114100
}

src/main/java/org/springframework/data/elasticsearch/core/query/ScriptType.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)