Dataes 768 add missing query parameters for an update query.
Original PR: #410
This commit is contained in:
committed by
GitHub
parent
f354f986ca
commit
f8630a09df
@@ -21,12 +21,23 @@ import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
@@ -69,4 +80,43 @@ public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
||||
@Id private String id;
|
||||
@Field(type = Text, store = true, fielddata = true) private String type;
|
||||
}
|
||||
|
||||
@Test // DATAES-768
|
||||
void shouldUseAllOptionsFromUpdateQuery() {
|
||||
Map<String, Object> doc = new HashMap<>();
|
||||
doc.put("id", "1");
|
||||
doc.put("message", "test");
|
||||
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
|
||||
.from(doc);
|
||||
UpdateQuery updateQuery = UpdateQuery.builder("1") //
|
||||
.withDocument(document) //
|
||||
.withIfSeqNo(42) //
|
||||
.withIfPrimaryTerm(13) //
|
||||
.withScript("script")//
|
||||
.withLang("lang") //
|
||||
.withRefresh(UpdateQuery.Refresh.Wait_For) //
|
||||
.withRetryOnConflict(7) //
|
||||
.withTimeout("4711s") //
|
||||
.withWaitForActiveShards("all") //
|
||||
.withFetchSourceIncludes(Collections.singletonList("incl")) //
|
||||
.withFetchSourceExcludes(Collections.singletonList("excl")) //
|
||||
.build();
|
||||
|
||||
UpdateRequest request = getRequestFactory().updateRequest(updateQuery, IndexCoordinates.of("index"));
|
||||
|
||||
assertThat(request).isNotNull();
|
||||
assertThat(request.ifSeqNo()).isEqualTo(42);
|
||||
assertThat(request.ifPrimaryTerm()).isEqualTo(13);
|
||||
assertThat(request.script().getIdOrCode()).isEqualTo("script");
|
||||
assertThat(request.script().getLang()).isEqualTo("lang");
|
||||
assertThat(request.getRefreshPolicy()).isEqualByComparingTo(WriteRequest.RefreshPolicy.WAIT_UNTIL);
|
||||
assertThat(request.retryOnConflict()).isEqualTo(7);
|
||||
assertThat(request.timeout()).isEqualByComparingTo(TimeValue.parseTimeValue("4711s", "test"));
|
||||
assertThat(request.waitForActiveShards()).isEqualTo(ActiveShardCount.ALL);
|
||||
val fetchSourceContext = request.fetchSource();
|
||||
assertThat(fetchSourceContext).isNotNull();
|
||||
assertThat(fetchSourceContext.includes()).containsExactlyInAnyOrder("incl");
|
||||
assertThat(fetchSourceContext.excludes()).containsExactlyInAnyOrder("excl");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.lang.Double;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Long;
|
||||
import java.lang.Object;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -20,9 +20,19 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.Object;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -83,6 +93,44 @@ public class ElasticsearchTransportTemplateTests extends ElasticsearchTemplateTe
|
||||
assertThat(searchRequestBuilder.request().source().from()).isEqualTo(30);
|
||||
}
|
||||
|
||||
@Test // DATAES-768
|
||||
void shouldUseAllOptionsFromUpdateQuery() {
|
||||
Map<String, Object> doc = new HashMap<>();
|
||||
doc.put("id", "1");
|
||||
doc.put("message", "test");
|
||||
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
|
||||
.from(doc);
|
||||
UpdateQuery updateQuery = UpdateQuery.builder("1") //
|
||||
.withDocument(document) //
|
||||
.withIfSeqNo(42) //
|
||||
.withIfPrimaryTerm(13) //
|
||||
.withScript("script")//
|
||||
.withLang("lang") //
|
||||
.withRefresh(UpdateQuery.Refresh.Wait_For) //
|
||||
.withRetryOnConflict(7) //
|
||||
.withTimeout("4711s") //
|
||||
.withWaitForActiveShards("all").withFetchSourceIncludes(Collections.singletonList("incl")) //
|
||||
.withFetchSourceExcludes(Collections.singletonList("excl")) //
|
||||
.build();
|
||||
|
||||
UpdateRequestBuilder request = getRequestFactory().updateRequestBuilderFor(client, updateQuery,
|
||||
IndexCoordinates.of("index"));
|
||||
|
||||
assertThat(request).isNotNull();
|
||||
assertThat(request.request().ifSeqNo()).isEqualTo(42);
|
||||
assertThat(request.request().ifPrimaryTerm()).isEqualTo(13);
|
||||
assertThat(request.request().script().getIdOrCode()).isEqualTo("script");
|
||||
assertThat(request.request().script().getLang()).isEqualTo("lang");
|
||||
assertThat(request.request().getRefreshPolicy()).isEqualByComparingTo(WriteRequest.RefreshPolicy.WAIT_UNTIL);
|
||||
assertThat(request.request().retryOnConflict()).isEqualTo(7);
|
||||
assertThat(request.request().timeout()).isEqualByComparingTo(TimeValue.parseTimeValue("4711s", "test"));
|
||||
assertThat(request.request().waitForActiveShards()).isEqualTo(ActiveShardCount.ALL);
|
||||
val fetchSourceContext = request.request().fetchSource();
|
||||
assertThat(fetchSourceContext).isNotNull();
|
||||
assertThat(fetchSourceContext.includes()).containsExactlyInAnyOrder("incl");
|
||||
assertThat(fetchSourceContext.excludes()).containsExactlyInAnyOrder("excl");
|
||||
}
|
||||
|
||||
@Data
|
||||
@Document(indexName = "test-index-sample-core-transport-template", replicas = 0, refreshInterval = "-1")
|
||||
static class SampleEntity {
|
||||
|
||||
Reference in New Issue
Block a user