mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 11:32:12 +00:00
Polishing
This commit is contained in:
parent
c5db583048
commit
4a0e7cc56e
@ -88,8 +88,8 @@ import org.elasticsearch.core.TimeValue;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||
import org.elasticsearch.index.reindex.ReindexRequest;
|
||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.script.mustache.SearchTemplateRequest;
|
||||
@ -105,7 +105,6 @@ import org.elasticsearch.xcontent.XContentType;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.data.elasticsearch.RestStatusException;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.core.ResponseConverter;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.ClientLogger;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
||||
@ -115,6 +114,7 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsea
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices;
|
||||
import org.springframework.data.elasticsearch.client.util.NamedXContents;
|
||||
import org.springframework.data.elasticsearch.client.util.ScrollState;
|
||||
import org.springframework.data.elasticsearch.core.ResponseConverter;
|
||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||
import org.springframework.data.util.Lazy;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -150,7 +150,6 @@ import org.springframework.web.reactive.function.client.WebClient.RequestBodySpe
|
||||
* @see ClientConfiguration
|
||||
* @see ReactiveRestClients
|
||||
*/
|
||||
// todo package private after refactoring
|
||||
public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient, Indices, Cluster {
|
||||
|
||||
private final HostProvider<?> hostProvider;
|
||||
@ -514,14 +513,12 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch
|
||||
|
||||
@Override
|
||||
public Mono<BulkByScrollResponse> reindex(HttpHeaders headers, ReindexRequest reindexRequest) {
|
||||
return sendRequest(reindexRequest, requestCreator.reindex(), BulkByScrollResponse.class, headers)
|
||||
.next();
|
||||
return sendRequest(reindexRequest, requestCreator.reindex(), BulkByScrollResponse.class, headers).next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<String> submitReindex(HttpHeaders headers, ReindexRequest reindexRequest) {
|
||||
return sendRequest(reindexRequest, requestCreator.submitReindex(), TaskSubmissionResponse.class, headers)
|
||||
.next()
|
||||
return sendRequest(reindexRequest, requestCreator.submitReindex(), TaskSubmissionResponse.class, headers).next()
|
||||
.map(TaskSubmissionResponse::getTask);
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ import org.elasticsearch.client.indices.*;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||
import org.elasticsearch.index.reindex.ReindexRequest;
|
||||
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
|
||||
import org.elasticsearch.script.mustache.SearchTemplateRequest;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
@ -784,6 +784,7 @@ public interface ReactiveElasticsearchClient {
|
||||
* @since 4.4
|
||||
*/
|
||||
Mono<String> submitReindex(HttpHeaders headers, ReindexRequest reindexRequest);
|
||||
|
||||
/**
|
||||
* Compose the actual command/s to run against Elasticsearch using the underlying {@link WebClient connection}.
|
||||
* {@link #execute(ReactiveElasticsearchClientCallback) Execute} selects an active server from the available ones and
|
||||
|
@ -294,10 +294,14 @@ public interface RequestCreator {
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
default Function<ReindexRequest, Request> reindex() { return RequestConverters::reindex; }
|
||||
default Function<ReindexRequest, Request> reindex() {
|
||||
return RequestConverters::reindex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
*/
|
||||
default Function<ReindexRequest, Request> submitReindex() { return RequestConverters::submitReindex; }
|
||||
default Function<ReindexRequest, Request> submitReindex() {
|
||||
return RequestConverters::submitReindex;
|
||||
}
|
||||
}
|
||||
|
@ -550,10 +550,13 @@ public class RequestConverters {
|
||||
if (reindexRequest.getDestination().isRequireAlias()) {
|
||||
params.putParam("require_alias", Boolean.TRUE.toString());
|
||||
}
|
||||
|
||||
if (reindexRequest.getScrollTime() != null) {
|
||||
params.putParam("scroll", reindexRequest.getScrollTime());
|
||||
}
|
||||
|
||||
params.putParam("slices", Integer.toString(reindexRequest.getSlices()));
|
||||
|
||||
if (reindexRequest.getMaxDocs() > -1) {
|
||||
params.putParam("max_docs", Integer.toString(reindexRequest.getMaxDocs()));
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ package org.springframework.data.elasticsearch.core;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||
@ -27,6 +25,8 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@ -327,10 +327,9 @@ public interface DocumentOperations {
|
||||
ByQueryResponse updateByQuery(UpdateQuery updateQuery, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Copies documents from a source to a destination.
|
||||
* The source can be any existing index, alias, or data stream. The destination must differ from the source.
|
||||
* For example, you cannot reindex a data stream into itself.
|
||||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
* Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The
|
||||
* destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
*
|
||||
* @param reindexRequest reindex request parameters
|
||||
* @return the reindex response
|
||||
@ -339,8 +338,7 @@ public interface DocumentOperations {
|
||||
ReindexResponse reindex(ReindexRequest reindexRequest);
|
||||
|
||||
/**
|
||||
* Submits a reindex task.
|
||||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
* Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
*
|
||||
* @param reindexRequest reindex request parameters
|
||||
* @return the task id
|
||||
|
@ -61,9 +61,7 @@ import org.springframework.data.elasticsearch.core.cluster.ClusterOperations;
|
||||
import org.springframework.data.elasticsearch.core.cluster.ElasticsearchClusterOperations;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||
@ -73,6 +71,8 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@ -265,7 +265,7 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
Assert.notNull(query, "query must not be null");
|
||||
Assert.notNull(index, "index must not be null");
|
||||
|
||||
final UpdateByQueryRequest updateByQueryRequest = requestFactory.updateByQueryRequest(query, index);
|
||||
UpdateByQueryRequest updateByQueryRequest = requestFactory.updateByQueryRequest(query, index);
|
||||
|
||||
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
|
||||
updateByQueryRequest.setRefresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
|
||||
@ -285,8 +285,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
|
||||
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
|
||||
|
||||
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
final BulkByScrollResponse bulkByScrollResponse = execute(
|
||||
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
BulkByScrollResponse bulkByScrollResponse = execute(
|
||||
client -> client.reindex(reindexRequest, RequestOptions.DEFAULT));
|
||||
return ResponseConverter.reindexResponseOf(bulkByScrollResponse);
|
||||
}
|
||||
@ -295,9 +295,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
public String submitReindex(ReindexRequest postReindexRequest) {
|
||||
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
|
||||
|
||||
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
return execute(
|
||||
client -> client.submitReindexTask(reindexRequest, RequestOptions.DEFAULT).getTask());
|
||||
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
return execute(client -> client.submitReindexTask(reindexRequest, RequestOptions.DEFAULT).getTask());
|
||||
}
|
||||
|
||||
public List<IndexedObjectInformation> doBulkOperation(List<?> queries, BulkOptions bulkOptions,
|
||||
|
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@ -30,6 +28,8 @@ import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@ -307,10 +307,9 @@ public interface ReactiveDocumentOperations {
|
||||
Mono<ByQueryResponse> updateByQuery(UpdateQuery updateQuery, IndexCoordinates index);
|
||||
|
||||
/**
|
||||
* Copies documents from a source to a destination.
|
||||
* The source can be any existing index, alias, or data stream. The destination must differ from the source.
|
||||
* For example, you cannot reindex a data stream into itself.
|
||||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
* Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The
|
||||
* destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
*
|
||||
* @param reindexRequest reindex request parameters
|
||||
* @return a {@link Mono} emitting the reindex response
|
||||
@ -319,8 +318,7 @@ public interface ReactiveDocumentOperations {
|
||||
Mono<ReindexResponse> reindex(ReindexRequest reindexRequest);
|
||||
|
||||
/**
|
||||
* Submits a reindex task.
|
||||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
* Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
|
||||
*
|
||||
* @param reindexRequest reindex request parameters
|
||||
* @return a {@link Mono} emitting the {@literal task} id.
|
||||
|
@ -70,8 +70,6 @@ import org.springframework.data.elasticsearch.core.event.ReactiveAfterConvertCal
|
||||
import org.springframework.data.elasticsearch.core.event.ReactiveAfterLoadCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.ReactiveAfterSaveCallback;
|
||||
import org.springframework.data.elasticsearch.core.event.ReactiveBeforeConvertCallback;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
@ -84,6 +82,8 @@ import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.routing.DefaultRoutingResolver;
|
||||
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
|
||||
import org.springframework.data.elasticsearch.core.suggest.response.Suggest;
|
||||
@ -618,7 +618,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
||||
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
|
||||
|
||||
return Mono.defer(() -> {
|
||||
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
return Mono.from(execute(client -> client.reindex(reindexRequest))).map(ResponseConverter::reindexResponseOf);
|
||||
});
|
||||
}
|
||||
@ -629,7 +629,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
|
||||
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
|
||||
|
||||
return Mono.defer(() -> {
|
||||
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
|
||||
return Mono.from(execute(client -> client.submitReindex(reindexRequest)));
|
||||
});
|
||||
}
|
||||
|
@ -92,17 +92,17 @@ import org.springframework.data.elasticsearch.core.index.AliasActions;
|
||||
import org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.index.GetTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Source;
|
||||
import org.springframework.data.elasticsearch.core.reindex.Remote;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Dest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Slice;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.core.query.RescorerQuery.ScoreMode;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Dest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Slice;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest.Source;
|
||||
import org.springframework.data.elasticsearch.core.reindex.Remote;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@ -398,51 +398,58 @@ class RequestFactory {
|
||||
*/
|
||||
public org.elasticsearch.index.reindex.ReindexRequest reindexRequest(ReindexRequest reindexRequest) {
|
||||
final org.elasticsearch.index.reindex.ReindexRequest request = new org.elasticsearch.index.reindex.ReindexRequest();
|
||||
|
||||
if (reindexRequest.getConflicts() != null) {
|
||||
request.setConflicts(reindexRequest.getConflicts().name().toLowerCase(Locale.ROOT));
|
||||
request.setConflicts(reindexRequest.getConflicts().getEsName());
|
||||
}
|
||||
|
||||
if (reindexRequest.getMaxDocs() != null) {
|
||||
request.setMaxDocs(reindexRequest.getMaxDocs());
|
||||
}
|
||||
// region source build
|
||||
final Source source = reindexRequest.getSource();
|
||||
request.setSourceIndices(source.getIndexes().getIndexNames());
|
||||
|
||||
// source query will build from RemoteInfo if remote exist
|
||||
if (source.getQuery() != null && source.getRemote() == null) {
|
||||
request.setSourceQuery(getQuery(source.getQuery()));
|
||||
}
|
||||
|
||||
if (source.getSize() != null) {
|
||||
request.setSourceBatchSize(source.getSize());
|
||||
}
|
||||
|
||||
if (source.getRemote() != null) {
|
||||
Remote remote = source.getRemote();
|
||||
QueryBuilder queryBuilder = source.getQuery() == null ? QueryBuilders.matchAllQuery() : getQuery(source.getQuery());
|
||||
QueryBuilder queryBuilder = source.getQuery() == null ? QueryBuilders.matchAllQuery()
|
||||
: getQuery(source.getQuery());
|
||||
BytesReference query;
|
||||
try {
|
||||
XContentBuilder builder = XContentBuilder.builder(QUERY_CONTENT_TYPE).prettyPrint();
|
||||
query = BytesReference.bytes(queryBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("an IOException occurs while building the source query content",e);
|
||||
throw new IllegalArgumentException("Error parsing the source query content", e);
|
||||
}
|
||||
request.setRemoteInfo(new RemoteInfo(
|
||||
remote.getScheme(),
|
||||
remote.getHost(),
|
||||
remote.getPort(),
|
||||
remote.getPathPrefix(),
|
||||
query,
|
||||
remote.getUsername(),
|
||||
remote.getPassword(),
|
||||
Collections.emptyMap(),
|
||||
remote.getSocketTimeout() == null ? DEFAULT_SOCKET_TIMEOUT : timeValueSeconds(remote.getSocketTimeout().getSeconds()),
|
||||
remote.getConnectTimeout() == null ? DEFAULT_CONNECT_TIMEOUT : timeValueSeconds(remote.getConnectTimeout().getSeconds())
|
||||
));
|
||||
request.setRemoteInfo(new RemoteInfo( //
|
||||
remote.getScheme(), //
|
||||
remote.getHost(), //
|
||||
remote.getPort(), //
|
||||
remote.getPathPrefix(), //
|
||||
query, //
|
||||
remote.getUsername(), //
|
||||
remote.getPassword(), //
|
||||
Collections.emptyMap(), //
|
||||
remote.getSocketTimeout() == null ? DEFAULT_SOCKET_TIMEOUT
|
||||
: timeValueSeconds(remote.getSocketTimeout().getSeconds()), //
|
||||
remote.getConnectTimeout() == null ? DEFAULT_CONNECT_TIMEOUT
|
||||
: timeValueSeconds(remote.getConnectTimeout().getSeconds()))); //
|
||||
}
|
||||
|
||||
final Slice slice = source.getSlice();
|
||||
if (slice != null) {
|
||||
request.getSearchRequest().source().slice(new SliceBuilder(slice.getId(), slice.getMax()));
|
||||
}
|
||||
|
||||
final SourceFilter sourceFilter = source.getSourceFilter();
|
||||
if (sourceFilter != null) {
|
||||
request.getSearchRequest().source().fetchSource(sourceFilter.getIncludes(), sourceFilter.getExcludes());
|
||||
@ -451,14 +458,14 @@ class RequestFactory {
|
||||
|
||||
// region dest build
|
||||
final Dest dest = reindexRequest.getDest();
|
||||
request.setDestIndex(dest.getIndex().getIndexName())
|
||||
.setDestRouting(dest.getRouting())
|
||||
request.setDestIndex(dest.getIndex().getIndexName()).setDestRouting(dest.getRouting())
|
||||
.setDestPipeline(dest.getPipeline());
|
||||
|
||||
final org.springframework.data.elasticsearch.annotations.Document.VersionType versionType = dest.getVersionType();
|
||||
if (versionType != null) {
|
||||
request.setDestVersionType(VersionType.fromString(versionType.name().toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
final IndexQuery.OpType opType = dest.getOpType();
|
||||
if (opType != null) {
|
||||
request.setDestOpType(opType.name().toLowerCase(Locale.ROOT));
|
||||
@ -468,11 +475,7 @@ class RequestFactory {
|
||||
// region script build
|
||||
final ReindexRequest.Script script = reindexRequest.getScript();
|
||||
if (script != null) {
|
||||
request.setScript(new Script(DEFAULT_SCRIPT_TYPE,
|
||||
script.getLang(),
|
||||
script.getSource(),
|
||||
Collections.emptyMap()
|
||||
));
|
||||
request.setScript(new Script(DEFAULT_SCRIPT_TYPE, script.getLang(), script.getSource(), Collections.emptyMap()));
|
||||
}
|
||||
// endregion
|
||||
|
||||
@ -481,22 +484,28 @@ class RequestFactory {
|
||||
if (timeout != null) {
|
||||
request.setTimeout(timeValueSeconds(timeout.getSeconds()));
|
||||
}
|
||||
|
||||
if (reindexRequest.getRefresh() != null) {
|
||||
request.setRefresh(reindexRequest.getRefresh());
|
||||
}
|
||||
|
||||
if (reindexRequest.getRequireAlias() != null) {
|
||||
request.setRequireAlias(reindexRequest.getRequireAlias());
|
||||
}
|
||||
|
||||
if (reindexRequest.getRequestsPerSecond() != null) {
|
||||
request.setRequestsPerSecond(reindexRequest.getRequestsPerSecond());
|
||||
}
|
||||
|
||||
final Duration scroll = reindexRequest.getScroll();
|
||||
if (scroll != null) {
|
||||
request.setScroll(timeValueSeconds(scroll.getSeconds()));
|
||||
}
|
||||
|
||||
if (reindexRequest.getWaitForActiveShards() != null) {
|
||||
request.setWaitForActiveShards(ActiveShardCount.parseString(reindexRequest.getWaitForActiveShards()));
|
||||
}
|
||||
|
||||
if (reindexRequest.getSlices() != null) {
|
||||
request.setSlices(reindexRequest.getSlices());
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasData;
|
||||
import org.springframework.data.elasticsearch.core.index.Settings;
|
||||
import org.springframework.data.elasticsearch.core.index.TemplateData;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
* Copyright 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.
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.reindex;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
@ -23,11 +25,9 @@ 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)
|
||||
* 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
|
||||
@ -50,7 +50,10 @@ public class ReindexRequest {
|
||||
@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) {
|
||||
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");
|
||||
@ -132,7 +135,18 @@ public class ReindexRequest {
|
||||
}
|
||||
|
||||
public enum Conflicts {
|
||||
PROCEED, ABORT
|
||||
PROCEED("proceed"), ABORT("abort");
|
||||
|
||||
// value used in Elasticsearch
|
||||
private final String esName;
|
||||
|
||||
Conflicts(String esName) {
|
||||
this.esName = esName;
|
||||
}
|
||||
|
||||
public String getEsName() {
|
||||
return esName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Source {
|
||||
@ -380,7 +394,8 @@ public class ReindexRequest {
|
||||
// endregion
|
||||
|
||||
public ReindexRequest build() {
|
||||
return new ReindexRequest(source, dest, maxDocs, conflicts, script, timeout, requireAlias, refresh, waitForActiveShards, requestsPerSecond, scroll, slices);
|
||||
return new ReindexRequest(source, dest, maxDocs, conflicts, script, timeout, requireAlias, refresh,
|
||||
waitForActiveShards, requestsPerSecond, scroll, slices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
* Copyright 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.
|
||||
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.reindex;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Response of reindex request.
|
||||
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-api-response-body)
|
||||
* Response of reindex request. (@see
|
||||
* https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-api-response-body)
|
||||
*
|
||||
* @author Sijia Liu
|
||||
* @since 4.4
|
||||
@ -45,8 +45,8 @@ public class ReindexResponse {
|
||||
private final List<Failure> failures;
|
||||
|
||||
private ReindexResponse(long took, boolean timedOut, long total, long updated, long deleted, int batches,
|
||||
long versionConflicts, long noops, long bulkRetries, long searchRetries,
|
||||
long throttledMillis, double requestsPerSecond, long throttledUntilMillis, List<Failure> failures) {
|
||||
long versionConflicts, long noops, long bulkRetries, long searchRetries, long throttledMillis,
|
||||
double requestsPerSecond, long throttledUntilMillis, List<Failure> failures) {
|
||||
this.took = took;
|
||||
this.timedOut = timedOut;
|
||||
this.total = total;
|
||||
@ -149,9 +149,9 @@ public class ReindexResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* This field should always be equal to zero in a _reindex response.
|
||||
* It only has meaning when using the Task API, where it indicates the next time (in milliseconds since epoch)
|
||||
* a throttled request will be executed again in order to conform to requests_per_second.
|
||||
* This field should always be equal to zero in a _reindex response. It only has meaning when using the Task API,
|
||||
* where it indicates the next time (in milliseconds since epoch) a throttled request will be executed again in order
|
||||
* to conform to requests_per_second.
|
||||
*/
|
||||
public long getThrottledUntilMillis() {
|
||||
return throttledUntilMillis;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
* Copyright 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.
|
||||
@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.reindex;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
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)
|
||||
* Remote info (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#source)
|
||||
*
|
||||
* @author Sijia Liu
|
||||
* @since 4.4
|
||||
@ -38,7 +37,8 @@ public class Remote {
|
||||
@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) {
|
||||
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");
|
||||
|
@ -83,11 +83,6 @@ import org.springframework.data.elasticsearch.annotations.JoinTypeRelations;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.ScriptField;
|
||||
import org.springframework.data.elasticsearch.core.document.Explanation;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasAction;
|
||||
@ -97,6 +92,8 @@ import org.springframework.data.elasticsearch.core.join.JoinField;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.core.query.RescorerQuery.ScoreMode;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
@ -3660,10 +3657,11 @@ public abstract class ElasticsearchTemplateTests {
|
||||
String destIndexName = indexNameProvider.indexName();
|
||||
operations.indexOps(IndexCoordinates.of(destIndexName)).create();
|
||||
|
||||
final ReindexRequest reindexRequest = ReindexRequest.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName))
|
||||
.withRefresh(true).build();
|
||||
final ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName)).withRefresh(true).build();
|
||||
final ReindexResponse reindex = operations.reindex(reindexRequest);
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
|
||||
assertThat(reindex.getTotal()).isEqualTo(1);
|
||||
assertThat(operations.count(searchQuery, IndexCoordinates.of(destIndexName))).isEqualTo(1);
|
||||
}
|
||||
@ -3677,7 +3675,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
final ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName)).build();
|
||||
String task = operations.submitReindex(reindexRequest);
|
||||
// Maybe there should be a task api to detect whether the task exists
|
||||
|
||||
assertThat(task).isNotBlank();
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@ import static java.util.Collections.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@ -80,6 +78,7 @@ import org.springframework.data.elasticsearch.core.index.AliasActions;
|
||||
import org.springframework.data.elasticsearch.core.index.AliasData;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ReactiveElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||
@ -1201,17 +1200,12 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
|
||||
String destIndexName = indexNameProvider.indexName();
|
||||
operations.indexOps(IndexCoordinates.of(destIndexName)).create();
|
||||
final ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName))
|
||||
.withRefresh(true)
|
||||
.build();
|
||||
operations.reindex(reindexRequest)
|
||||
.as(StepVerifier::create)
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName)).withRefresh(true).build();
|
||||
operations.reindex(reindexRequest).as(StepVerifier::create)
|
||||
.consumeNextWith(postReindexResponse -> assertThat(postReindexResponse.getTotal()).isEqualTo(1L))
|
||||
.verifyComplete();
|
||||
operations.count(operations.matchAllQuery(), SampleEntity.class, IndexCoordinates.of(destIndexName))
|
||||
.as(StepVerifier::create)
|
||||
.expectNext(1L)
|
||||
.verifyComplete();
|
||||
.as(StepVerifier::create).expectNext(1L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #1529
|
||||
@ -1221,12 +1215,9 @@ public class ReactiveElasticsearchTemplateIntegrationTests {
|
||||
String destIndexName = indexNameProvider.indexName();
|
||||
operations.indexOps(IndexCoordinates.of(destIndexName)).create();
|
||||
final ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName))
|
||||
.build();
|
||||
operations.submitReindex(reindexRequest)
|
||||
.as(StepVerifier::create)
|
||||
.consumeNextWith(task -> assertThat(task).isNotBlank())
|
||||
.verifyComplete();
|
||||
.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName)).build();
|
||||
operations.submitReindex(reindexRequest).as(StepVerifier::create)
|
||||
.consumeNextWith(task -> assertThat(task).isNotBlank()).verifyComplete();
|
||||
}
|
||||
// endregion
|
||||
|
||||
|
@ -560,56 +560,46 @@ class RequestFactoryTests {
|
||||
|
||||
@Test // #1529
|
||||
void shouldCreateReindexRequest() throws IOException, JSONException {
|
||||
final String expected = "{\n" +
|
||||
" \"source\":{\n" +
|
||||
" \"remote\":{\n" +
|
||||
" \"username\":\"admin\",\n" +
|
||||
" \"password\":\"password\",\n" +
|
||||
" \"host\":\"http://localhost:9200/elasticsearch\",\n" +
|
||||
" \"socket_timeout\":\"30s\",\n" +
|
||||
" \"connect_timeout\":\"30s\"\n" +
|
||||
" },\n" +
|
||||
" \"index\":[\"source_1\",\"source_2\"],\n" +
|
||||
" \"size\":5,\n" +
|
||||
" \"query\":{\"match_all\":{}},\n" +
|
||||
" \"_source\":{\"includes\":[\"name\"],\"excludes\":[]},\n" +
|
||||
" \"slice\":{\"id\":1,\"max\":20}\n" +
|
||||
" },\n" +
|
||||
" \"dest\":{\n" +
|
||||
" \"index\":\"destination\",\n" +
|
||||
" \"routing\":\"routing\",\n" +
|
||||
" \"op_type\":\"create\",\n" +
|
||||
" \"pipeline\":\"pipeline\",\n" +
|
||||
" \"version_type\":\"external\"\n" +
|
||||
" },\n" +
|
||||
" \"max_docs\":10,\n" +
|
||||
" \"script\":{\"source\":\"Math.max(1,2)\",\"lang\":\"java\"},\n" +
|
||||
" \"conflicts\":\"proceed\"\n" +
|
||||
final String expected = "{\n" + //
|
||||
" \"source\":{\n" + //
|
||||
" \"remote\":{\n" + //
|
||||
" \"username\":\"admin\",\n" + //
|
||||
" \"password\":\"password\",\n" + //
|
||||
" \"host\":\"http://localhost:9200/elasticsearch\",\n" + //
|
||||
" \"socket_timeout\":\"30s\",\n" + //
|
||||
" \"connect_timeout\":\"30s\"\n" + //
|
||||
" },\n" + //
|
||||
" \"index\":[\"source_1\",\"source_2\"],\n" + //
|
||||
" \"size\":5,\n" + //
|
||||
" \"query\":{\"match_all\":{}},\n" + //
|
||||
" \"_source\":{\"includes\":[\"name\"],\"excludes\":[]},\n" + //
|
||||
" \"slice\":{\"id\":1,\"max\":20}\n" + //
|
||||
" },\n" + //
|
||||
" \"dest\":{\n" + //
|
||||
" \"index\":\"destination\",\n" + //
|
||||
" \"routing\":\"routing\",\n" + //
|
||||
" \"op_type\":\"create\",\n" + //
|
||||
" \"pipeline\":\"pipeline\",\n" + //
|
||||
" \"version_type\":\"external\"\n" + //
|
||||
" },\n" + //
|
||||
" \"max_docs\":10,\n" + //
|
||||
" \"script\":{\"source\":\"Math.max(1,2)\",\"lang\":\"java\"},\n" + //
|
||||
" \"conflicts\":\"proceed\"\n" + //
|
||||
"}";
|
||||
|
||||
Remote remote = Remote.builder("http", "localhost",9200)
|
||||
.withPathPrefix("elasticsearch")
|
||||
.withUsername("admin")
|
||||
.withPassword("password")
|
||||
.withConnectTimeout(Duration.ofSeconds(30))
|
||||
.withSocketTimeout(Duration.ofSeconds(30)).build();
|
||||
|
||||
ReindexRequest reindexRequest = ReindexRequest.builder(IndexCoordinates.of("source_1", "source_2"),
|
||||
IndexCoordinates.of("destination"))
|
||||
.withConflicts(ReindexRequest.Conflicts.PROCEED)
|
||||
.withMaxDocs(10)
|
||||
.withSourceQuery(new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build())
|
||||
.withSourceSize(5)
|
||||
.withSourceSourceFilter(new FetchSourceFilterBuilder().withIncludes("name").build())
|
||||
.withSourceRemote(remote)
|
||||
.withSourceSlice(1,20)
|
||||
.withDestOpType(IndexQuery.OpType.CREATE)
|
||||
.withDestVersionType(Document.VersionType.EXTERNAL)
|
||||
.withDestPipeline("pipeline")
|
||||
.withDestRouting("routing")
|
||||
.withScript("Math.max(1,2)", "java")
|
||||
Remote remote = Remote.builder("http", "localhost", 9200).withPathPrefix("elasticsearch").withUsername("admin")
|
||||
.withPassword("password").withConnectTimeout(Duration.ofSeconds(30)).withSocketTimeout(Duration.ofSeconds(30))
|
||||
.build();
|
||||
|
||||
ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of("source_1", "source_2"), IndexCoordinates.of("destination"))
|
||||
.withConflicts(ReindexRequest.Conflicts.PROCEED).withMaxDocs(10)
|
||||
.withSourceQuery(new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build()).withSourceSize(5)
|
||||
.withSourceSourceFilter(new FetchSourceFilterBuilder().withIncludes("name").build()).withSourceRemote(remote)
|
||||
.withSourceSlice(1, 20).withDestOpType(IndexQuery.OpType.CREATE)
|
||||
.withDestVersionType(Document.VersionType.EXTERNAL).withDestPipeline("pipeline").withDestRouting("routing")
|
||||
.withScript("Math.max(1,2)", "java").build();
|
||||
|
||||
final String json = requestToString(requestFactory.reindexRequest(reindexRequest));
|
||||
|
||||
assertEquals(expected, json, false);
|
||||
@ -617,22 +607,21 @@ class RequestFactoryTests {
|
||||
|
||||
@Test
|
||||
void shouldAllowSourceQueryForReindexWithoutRemote() throws IOException, JSONException {
|
||||
final String expected = "{\n" +
|
||||
" \"source\":{\n" +
|
||||
" \"index\":[\"source\"],\n" +
|
||||
" \"query\":{\"match_all\":{}}\n" +
|
||||
" },\n" +
|
||||
" \"dest\":{\n" +
|
||||
" \"index\":\"destination\",\n" +
|
||||
" \"op_type\":\"index\",\n" +
|
||||
" \"version_type\":\"internal\"\n" +
|
||||
" }\n" +
|
||||
final String expected = "{\n" + //
|
||||
" \"source\":{\n" + //
|
||||
" \"index\":[\"source\"],\n" + //
|
||||
" \"query\":{\"match_all\":{}}\n" + //
|
||||
" },\n" + //
|
||||
" \"dest\":{\n" + //
|
||||
" \"index\":\"destination\",\n" + //
|
||||
" \"op_type\":\"index\",\n" + //
|
||||
" \"version_type\":\"internal\"\n" + //
|
||||
" }\n" + //
|
||||
"}";
|
||||
|
||||
ReindexRequest reindexRequest = ReindexRequest.builder(IndexCoordinates.of("source"),
|
||||
IndexCoordinates.of("destination"))
|
||||
.withSourceQuery(new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build())
|
||||
.build();
|
||||
ReindexRequest reindexRequest = ReindexRequest
|
||||
.builder(IndexCoordinates.of("source"), IndexCoordinates.of("destination"))
|
||||
.withSourceQuery(new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build()).build();
|
||||
|
||||
final String json = requestToString(requestFactory.reindexRequest(reindexRequest));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user