Skip to content

Elasticsearch 9.0 update #3116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<springdata.commons>4.0.0-SNAPSHOT</springdata.commons>

<!-- version of the ElasticsearchClient -->
<elasticsearch-java>8.18.1</elasticsearch-java>
<elasticsearch-java>9.0.1</elasticsearch-java>

<hoverfly>0.19.0</hoverfly>
<log4j>2.23.1</log4j>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static SearchDocument from(Hit<?> hit, JsonpMapper jsonpMapper) {

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

List<String> matchedQueries = hit.matchedQueries();
Map<String, Double> matchedQueries = hit.matchedQueries();

Function<Map<String, JsonData>, EntityAsMap> fromFields = fields -> {
StringBuilder sb = new StringBuilder("{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,6 @@ public Mono<IndicesStatsResponse> stats() {
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) {
return Mono.fromFuture(transport.performRequestAsync(request, UpdateAliasesRequest._ENDPOINT, transportOptions));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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())) //
Expand Down Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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<String, JsonData> params = getTemplateParams(query.getParams().entrySet());
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -1551,7 +1555,9 @@ private <T> 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()));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()) //
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, IndexMappingRecord> mappings = getMappingResponse.result();
Map<String, IndexMappingRecord> mappings = getMappingResponse.mappings();

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

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))
: new Settings();
Document mappings = indexState.mappings() != null ? Document.parse(toJson(indexState.mappings(), jsonpMapper))
Expand All @@ -239,7 +239,7 @@ public Map<String, Set<AliasData>> indicesGetAliasData(GetAliasResponse getAlias
Assert.notNull(getAliasResponse, "getAliasResponse must not be null");

Map<String, Set<AliasData>> aliasDataMap = new HashMap<>();
getAliasResponse.result().forEach((indexName, alias) -> {
getAliasResponse.aliases().forEach((indexName, alias) -> {
Set<AliasData> aliasDataSet = new HashSet<>();
alias.aliases()
.forEach((aliasName, aliasDefinition) -> aliasDataSet.add(indicesGetAliasData(aliasName, aliasDefinition)));
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public class SearchHit<T> {
@Nullable private final NestedMetaData nestedMetaData;
@Nullable private final String routing;
@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,
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields,
@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.id = id;
this.routing = routing;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public Explanation getExplanation() {
* @return the matched queries for this SearchHit.
*/
@Nullable
public List<String> getMatchedQueries() {
public Map<String, Double> getMatchedQueries() {
return matchedQueries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ default String getRouting() {
* @return the matched queries for the SearchHit.
*/
@Nullable
List<String> getMatchedQueries();
Map<String, Double> getMatchedQueries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class SearchDocumentAdapter implements SearchDocument {
private final Map<String, SearchDocumentResponse> innerHits = new HashMap<>();
@Nullable private final NestedMetaData nestedMetaData;
@Nullable private final Explanation explanation;
@Nullable private final List<String> matchedQueries;
@Nullable private final Map<String, Double> matchedQueries;
@Nullable private final String routing;

public SearchDocumentAdapter(Document delegate, float score, Object[] sortValues, Map<String, List<Object>> fields,
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) {

this.delegate = delegate;
Expand Down Expand Up @@ -249,7 +249,7 @@ public Explanation getExplanation() {

@Override
@Nullable
public List<String> getMatchedQueries() {
public Map<String, Double> getMatchedQueries() {
return matchedQueries;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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) {

Assert.notNull(type, "type must not be null");

this.type = type;
this.language = language;
this.script = script;
this.scriptName = scriptName;
Expand All @@ -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<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) {
Expand All @@ -68,22 +65,13 @@ 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;
@Nullable private Map<String, Object> params;

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;
Expand All @@ -106,9 +94,7 @@ public Builder withParams(@Nullable Map<String, Object> 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);
}
}
}

This file was deleted.

Loading