Skip to content

Commit 158f5fc

Browse files
authored
es java client major update.
Original Pull Request #3116 Closes #3110 Signed-off-by: Laura Trotta <[email protected]>
1 parent 6268133 commit 158f5fc

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>4.0.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;
@@ -751,11 +751,10 @@ private CreateOperation<?> bulkCreateOperation(IndexQuery query, IndexCoordinate
751751
}
752752
return co.elastic.clients.elasticsearch._types.Script.of(sb -> {
753753
sb.lang(scriptData.language())
754-
.params(params);
755-
if (scriptData.type() == ScriptType.INLINE) {
756-
sb.source(scriptData.script());
757-
} else if (scriptData.type() == ScriptType.STORED) {
758-
sb.id(scriptData.script());
754+
.params(params)
755+
.id(scriptData.scriptName());
756+
if (scriptData.script() != null){
757+
sb.source(s -> s.scriptString(scriptData.script()));
759758
}
760759
return sb;
761760
});
@@ -927,9 +926,13 @@ public co.elastic.clients.elasticsearch.core.ReindexRequest reindex(ReindexReque
927926

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

935938
builder.timeout(time(reindexRequest.getTimeout())) //
@@ -1086,12 +1089,11 @@ public DeleteByQueryRequest documentDeleteByQueryRequest(DeleteQuery query, @Nul
10861089

10871090
uqb.script(sb -> {
10881091
sb.lang(query.getLang()).params(params);
1089-
1090-
if (query.getScriptType() == ScriptType.INLINE) {
1091-
sb.source(query.getScript()); //
1092-
} else if (query.getScriptType() == ScriptType.STORED) {
1093-
sb.id(query.getScript());
1092+
if (query.getScript() != null){
1093+
sb.source(s -> s.scriptString(query.getScript()));
10941094
}
1095+
sb.id(query.getId());
1096+
10951097
return sb;
10961098
});
10971099
}
@@ -1254,11 +1256,11 @@ public MsearchTemplateRequest searchMsearchTemplateRequest(
12541256
mtrb.searchTemplates(stb -> stb
12551257
.header(msearchHeaderBuilder(query, param.index(), routing))
12561258
.body(bb -> {
1257-
bb //
1258-
.explain(query.getExplain()) //
1259-
.id(query.getId()) //
1260-
.source(query.getSource()) //
1261-
;
1259+
bb.explain(query.getExplain()) //
1260+
.id(query.getId()); //
1261+
if (query.getSource() != null){
1262+
bb.source(s -> s.scriptString(query.getSource()));
1263+
}
12621264

12631265
if (!CollectionUtils.isEmpty(query.getParams())) {
12641266
Map<String, JsonData> params = getTemplateParams(query.getParams().entrySet());
@@ -1349,7 +1351,9 @@ public MsearchRequest searchMsearchRequest(
13491351

13501352
if (script != null) {
13511353
rfb.script(s -> {
1352-
s.source(script);
1354+
if (script != null) {
1355+
s.source(so -> so.scriptString(script));
1356+
}
13531357

13541358
if (runtimeField.getParams() != null) {
13551359
s.params(TypeUtils.paramsMap(runtimeField.getParams()));
@@ -1551,7 +1555,9 @@ private <T> void prepareSearchRequest(Query query, @Nullable String routing, @Nu
15511555
String script = runtimeField.getScript();
15521556
if (script != null) {
15531557
rfb.script(s -> {
1554-
s.source(script);
1558+
if (script != null) {
1559+
s.source(so -> so.scriptString(script));
1560+
}
15551561

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

1651-
private void addHighlight(Query query, MultisearchBody.Builder builder) {
1657+
private void addHighlight(Query query, SearchRequestBody.Builder builder) {
16521658

16531659
Highlight highlight = query.getHighlightQuery()
16541660
.map(highlightQuery -> new HighlightQueryBuilder(elasticsearchConverter.getMappingContext(), this)
@@ -1772,7 +1778,7 @@ private void prepareNativeSearch(NativeQuery query, SearchRequest.Builder builde
17721778
}
17731779

17741780
@SuppressWarnings("DuplicatedCode")
1775-
private void prepareNativeSearch(NativeQuery query, MultisearchBody.Builder builder) {
1781+
private void prepareNativeSearch(NativeQuery query, SearchRequestBody.Builder builder) {
17761782

17771783
builder //
17781784
.suggest(query.getSuggester()) //
@@ -1891,10 +1897,11 @@ public SearchTemplateRequest searchTemplate(SearchTemplateQuery query, @Nullable
18911897
.id(query.getId()) //
18921898
.index(Arrays.asList(index.getIndexNames())) //
18931899
.preference(query.getPreference()) //
1894-
.searchType(searchType(query.getSearchType())) //
1895-
.source(query.getSource()) //
1896-
;
1900+
.searchType(searchType(query.getSearchType())); //
18971901

1902+
if (query.getSource() != null) {
1903+
builder.source(so -> so.scriptString(query.getSource()));
1904+
}
18981905
if (query.getRoute() != null) {
18991906
builder.routing(query.getRoute());
19001907
} else if (StringUtils.hasText(routing)) {
@@ -1936,8 +1943,8 @@ public PutScriptRequest scriptPut(Script script) {
19361943
return PutScriptRequest.of(b -> b //
19371944
.id(script.id()) //
19381945
.script(sb -> sb //
1939-
.lang(script.language()) //
1940-
.source(script.source())));
1946+
.lang(script.language()) //
1947+
.source(s -> s.scriptString(script.source()))));
19411948
}
19421949

19431950
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)));
@@ -535,7 +535,7 @@ public Script scriptResponse(GetScriptResponse response) {
535535
? Script.builder() //
536536
.withId(response.id()) //
537537
.withLanguage(response.script().lang()) //
538-
.withSource(response.script().source()).build() //
538+
.withSource(response.script().source().scriptString()).build() //
539539
: null;
540540
}
541541
// 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)