-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement support for reindex API [DATAES-955] #1529 #2070
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
+1,479
−20
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e44b7cb
Implementing - Native query with ext section for SearchPlugin
oni7uka dc6d7a0
Merge branch 'main' of https://github.com/oni7uka/spring-data-elastic…
oni7uka 84eac20
Implement support for reindex API [DATAES-955] #1529
oni7uka 269a227
Merge branch 'main' of https://github.com/oni7uka/spring-data-elastic…
oni7uka 4f7a679
Use IndexCoordinates instead of String indexName
oni7uka 3744028
Update src/main/java/org/springframework/data/elasticsearch/core/Resp…
oni7uka d3243fc
Update src/test/java/org/springframework/data/elasticsearch/core/Reac…
oni7uka 7739550
move to upper level package
oni7uka addf096
rename ReindexRequest and ReindexResponse
oni7uka e331855
fix source queries must be allowed for reindexing without a remote
oni7uka 72a872f
Merge branch 'main' of https://github.com/oni7uka/spring-data-elastic…
oni7uka 8a0ca5c
Merge branch 'main' into main
oni7uka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
386 changes: 386 additions & 0 deletions
386
src/main/java/org/springframework/data/elasticsearch/core/reindex/ReindexRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,386 @@ | ||
/* | ||
* Copyright 2019-2022 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.reindex; | ||
|
||
import org.springframework.data.elasticsearch.annotations.Document; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; | ||
import org.springframework.data.elasticsearch.core.query.IndexQuery; | ||
import org.springframework.data.elasticsearch.core.query.Query; | ||
import org.springframework.data.elasticsearch.core.query.SourceFilter; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Request to reindex some documents from one index to another. | ||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) | ||
* | ||
* @author Sijia Liu | ||
* @since 4.4 | ||
*/ | ||
public class ReindexRequest { | ||
|
||
// Request body | ||
private final Source source; | ||
private final Dest dest; | ||
@Nullable private final Integer maxDocs; | ||
@Nullable private final Conflicts conflicts; | ||
@Nullable private final Script script; | ||
|
||
// Query parameters | ||
@Nullable private final Duration timeout; | ||
@Nullable private final Boolean requireAlias; | ||
@Nullable private final Boolean refresh; | ||
@Nullable private final String waitForActiveShards; | ||
@Nullable private final Integer requestsPerSecond; | ||
@Nullable private final Duration scroll; | ||
@Nullable private final Integer slices; | ||
|
||
private ReindexRequest(Source source, Dest dest, @Nullable Integer maxDocs, @Nullable Conflicts conflicts, @Nullable Script script, @Nullable Duration timeout, @Nullable Boolean requireAlias, @Nullable Boolean refresh, @Nullable String waitForActiveShards, @Nullable Integer requestsPerSecond, @Nullable Duration scroll, @Nullable Integer slices) { | ||
|
||
Assert.notNull(source, "source must not be null"); | ||
Assert.notNull(dest, "dest must not be null"); | ||
|
||
this.source = source; | ||
this.dest = dest; | ||
this.maxDocs = maxDocs; | ||
this.conflicts = conflicts; | ||
this.script = script; | ||
this.timeout = timeout; | ||
this.requireAlias = requireAlias; | ||
this.refresh = refresh; | ||
this.waitForActiveShards = waitForActiveShards; | ||
this.requestsPerSecond = requestsPerSecond; | ||
this.scroll = scroll; | ||
this.slices = slices; | ||
} | ||
|
||
@Nullable | ||
public Integer getMaxDocs() { | ||
return maxDocs; | ||
} | ||
|
||
public Source getSource() { | ||
return source; | ||
} | ||
|
||
public Dest getDest() { | ||
return dest; | ||
} | ||
|
||
@Nullable | ||
public Script getScript() { | ||
return script; | ||
} | ||
|
||
@Nullable | ||
public Conflicts getConflicts() { | ||
return conflicts; | ||
} | ||
|
||
@Nullable | ||
public Boolean getRequireAlias() { | ||
return requireAlias; | ||
} | ||
|
||
@Nullable | ||
public Duration getTimeout() { | ||
return timeout; | ||
} | ||
|
||
@Nullable | ||
public Boolean getRefresh() { | ||
return refresh; | ||
} | ||
|
||
@Nullable | ||
public String getWaitForActiveShards() { | ||
return waitForActiveShards; | ||
} | ||
|
||
@Nullable | ||
public Integer getRequestsPerSecond() { | ||
return requestsPerSecond; | ||
} | ||
|
||
@Nullable | ||
public Duration getScroll() { | ||
return scroll; | ||
} | ||
|
||
@Nullable | ||
public Integer getSlices() { | ||
return slices; | ||
} | ||
|
||
public static ReindexRequestBuilder builder(IndexCoordinates sourceIndex, IndexCoordinates destIndex) { | ||
return new ReindexRequestBuilder(sourceIndex, destIndex); | ||
} | ||
|
||
public enum Conflicts { | ||
PROCEED, ABORT | ||
} | ||
|
||
public static class Source { | ||
private final IndexCoordinates indexes; | ||
@Nullable private Query query; | ||
@Nullable private Remote remote; | ||
@Nullable private Slice slice; | ||
@Nullable private Integer size; | ||
@Nullable private SourceFilter sourceFilter; | ||
|
||
private Source(IndexCoordinates indexes){ | ||
Assert.notNull(indexes, "indexes must not be null"); | ||
|
||
this.indexes = indexes; | ||
} | ||
|
||
public IndexCoordinates getIndexes() { | ||
return indexes; | ||
} | ||
|
||
@Nullable | ||
public Remote getRemote() { | ||
return remote; | ||
} | ||
|
||
@Nullable | ||
public Query getQuery() { | ||
return query; | ||
} | ||
|
||
@Nullable | ||
public Integer getSize() { | ||
return size; | ||
} | ||
|
||
@Nullable | ||
public Slice getSlice() { | ||
return slice; | ||
} | ||
|
||
@Nullable | ||
public SourceFilter getSourceFilter() { | ||
return sourceFilter; | ||
} | ||
} | ||
|
||
public static class Slice { | ||
private final int id; | ||
private final int max; | ||
|
||
private Slice(int id, int max) { | ||
this.id = id; | ||
this.max = max; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public int getMax() { | ||
return max; | ||
} | ||
} | ||
|
||
public static class Dest { | ||
|
||
private final IndexCoordinates index; | ||
@Nullable private String pipeline; | ||
@Nullable private String routing; | ||
@Nullable private Document.VersionType versionType; | ||
@Nullable private IndexQuery.OpType opType; | ||
|
||
private Dest(IndexCoordinates index) { | ||
Assert.notNull(index, "dest index must not be null"); | ||
|
||
this.index = index; | ||
} | ||
|
||
public IndexCoordinates getIndex() { | ||
return index; | ||
} | ||
|
||
@Nullable | ||
public Document.VersionType getVersionType() { | ||
return versionType; | ||
} | ||
|
||
@Nullable | ||
public IndexQuery.OpType getOpType() { | ||
return opType; | ||
} | ||
|
||
@Nullable | ||
public String getPipeline() { | ||
return pipeline; | ||
} | ||
|
||
@Nullable | ||
public String getRouting() { | ||
return routing; | ||
} | ||
} | ||
|
||
public static class Script { | ||
private final String source; | ||
@Nullable private final String lang; | ||
|
||
private Script(String source, @Nullable String lang) { | ||
Assert.notNull(source, "source must not be null"); | ||
|
||
this.source = source; | ||
this.lang = lang; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
@Nullable | ||
public String getLang() { | ||
return lang; | ||
} | ||
} | ||
|
||
public static final class ReindexRequestBuilder { | ||
|
||
private final Source source; | ||
private final Dest dest; | ||
@Nullable private Integer maxDocs; | ||
@Nullable private Conflicts conflicts; | ||
@Nullable private Script script; | ||
@Nullable private Duration timeout; | ||
@Nullable private Boolean requireAlias; | ||
@Nullable private Boolean refresh; | ||
@Nullable private String waitForActiveShards; | ||
@Nullable private Integer requestsPerSecond; | ||
@Nullable private Duration scroll; | ||
@Nullable private Integer slices; | ||
|
||
public ReindexRequestBuilder(IndexCoordinates sourceIndex, IndexCoordinates destIndex) { | ||
|
||
Assert.notNull(sourceIndex, "sourceIndex must not be null"); | ||
Assert.notNull(destIndex, "destIndex must not be null"); | ||
|
||
this.source = new Source(sourceIndex); | ||
this.dest = new Dest(destIndex); | ||
} | ||
|
||
// region setter | ||
|
||
public ReindexRequestBuilder withMaxDocs(@Nullable Integer maxDocs) { | ||
this.maxDocs = maxDocs; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withConflicts(Conflicts conflicts) { | ||
this.conflicts = conflicts; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSourceQuery(Query query) { | ||
this.source.query = query; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSourceSlice(int id, int max){ | ||
this.source.slice = new Slice(id, max); | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSourceRemote(Remote remote) { | ||
this.source.remote = remote; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSourceSize(int size) { | ||
this.source.size = size; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSourceSourceFilter(SourceFilter sourceFilter){ | ||
this.source.sourceFilter = sourceFilter; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withDestPipeline(String pipelineName){ | ||
this.dest.pipeline = pipelineName; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withDestRouting(String routing){ | ||
this.dest.routing = routing; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withDestVersionType(Document.VersionType versionType) { | ||
this.dest.versionType = versionType; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withDestOpType(IndexQuery.OpType opType) { | ||
this.dest.opType = opType; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withScript(String source, @Nullable String lang) { | ||
this.script = new Script(source, lang); | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withTimeout(Duration timeout){ | ||
this.timeout = timeout; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withRequireAlias(boolean requireAlias){ | ||
this.requireAlias = requireAlias; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withRefresh(boolean refresh){ | ||
this.refresh = refresh; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withWaitForActiveShards(String waitForActiveShards){ | ||
this.waitForActiveShards = waitForActiveShards; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withRequestsPerSecond(int requestsPerSecond){ | ||
this.requestsPerSecond = requestsPerSecond; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withScroll(Duration scroll){ | ||
this.scroll = scroll; | ||
return this; | ||
} | ||
|
||
public ReindexRequestBuilder withSlices(int slices){ | ||
this.slices = slices; | ||
return this; | ||
} | ||
// endregion | ||
|
||
public ReindexRequest build() { | ||
return new ReindexRequest(source, dest, maxDocs, conflicts, script, timeout, requireAlias, refresh, waitForActiveShards, requestsPerSecond, scroll, slices); | ||
} | ||
} | ||
} |
403 changes: 403 additions & 0 deletions
403
src/main/java/org/springframework/data/elasticsearch/core/reindex/ReindexResponse.java
Large diffs are not rendered by default.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
src/main/java/org/springframework/data/elasticsearch/core/reindex/Remote.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright 2019-2022 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.reindex; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Remote info | ||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#source) | ||
* | ||
* @author Sijia Liu | ||
* @since 4.4 | ||
*/ | ||
public class Remote { | ||
private final String scheme; | ||
private final String host; | ||
private final int port; | ||
|
||
@Nullable private final String pathPrefix; | ||
@Nullable private final String username; | ||
@Nullable private final String password; | ||
@Nullable private final Duration socketTimeout; | ||
@Nullable private final Duration connectTimeout; | ||
|
||
private Remote(String scheme, String host, int port, @Nullable String pathPrefix, @Nullable String username, @Nullable String password, @Nullable Duration socketTimeout, @Nullable Duration connectTimeout) { | ||
|
||
Assert.notNull(scheme, "scheme must not be null"); | ||
Assert.notNull(host, "host must not be null"); | ||
|
||
this.scheme = scheme; | ||
this.host = host; | ||
this.port = port; | ||
this.pathPrefix = pathPrefix; | ||
this.username = username; | ||
this.password = password; | ||
this.socketTimeout = socketTimeout; | ||
this.connectTimeout = connectTimeout; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
@Nullable | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@Nullable | ||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
@Nullable | ||
public Duration getSocketTimeout() { | ||
return socketTimeout; | ||
} | ||
|
||
@Nullable | ||
public Duration getConnectTimeout() { | ||
return connectTimeout; | ||
} | ||
|
||
public String getScheme() { | ||
return scheme; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
@Nullable | ||
public String getPathPrefix() { | ||
return pathPrefix; | ||
} | ||
|
||
public static RemoteBuilder builder(String scheme, String host, int port){ | ||
return new RemoteBuilder(scheme, host, port); | ||
} | ||
|
||
public static class RemoteBuilder{ | ||
private final String scheme; | ||
private final String host; | ||
private final int port; | ||
@Nullable private String pathPrefix; | ||
@Nullable private String username; | ||
@Nullable private String password; | ||
@Nullable private Duration socketTimeout; | ||
@Nullable private Duration connectTimeout; | ||
|
||
public RemoteBuilder(String scheme, String host, int port) { | ||
this.scheme = scheme; | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
public RemoteBuilder withPathPrefix(String pathPrefix){ | ||
this.pathPrefix = pathPrefix; | ||
return this; | ||
} | ||
|
||
public RemoteBuilder withUsername(String username){ | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public RemoteBuilder withPassword(String password){ | ||
this.password = password; | ||
return this; | ||
} | ||
|
||
public RemoteBuilder withSocketTimeout(Duration socketTimeout){ | ||
this.socketTimeout = socketTimeout; | ||
return this; | ||
} | ||
|
||
public RemoteBuilder withConnectTimeout(Duration connectTimeout){ | ||
this.connectTimeout = connectTimeout; | ||
return this; | ||
} | ||
|
||
public Remote build(){ | ||
return new Remote(scheme, host, port , pathPrefix, username, password, socketTimeout, connectTimeout); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/org/springframework/data/elasticsearch/core/reindex/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@org.springframework.lang.NonNullApi | ||
@org.springframework.lang.NonNullFields | ||
package org.springframework.data.elasticsearch.core.reindex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.