mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-23 04:22:12 +00:00
DATAES-693 - Support for source fetching in update operations.
Original PR: #346
This commit is contained in:
parent
eba23eeb17
commit
79d75f814c
@ -145,6 +145,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
* @author Mathias Teier
|
* @author Mathias Teier
|
||||||
* @author Gyula Attila Csorogi
|
* @author Gyula Attila Csorogi
|
||||||
|
* @author Massimiliano Poggi
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
||||||
implements EsClient<RestHighLevelClient>, ApplicationContextAware {
|
implements EsClient<RestHighLevelClient>, ApplicationContextAware {
|
||||||
@ -685,7 +686,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
|||||||
.setRefreshPolicy(queryUpdateRequest.getRefreshPolicy()) //
|
.setRefreshPolicy(queryUpdateRequest.getRefreshPolicy()) //
|
||||||
.waitForActiveShards(queryUpdateRequest.waitForActiveShards()) //
|
.waitForActiveShards(queryUpdateRequest.waitForActiveShards()) //
|
||||||
.scriptedUpsert(queryUpdateRequest.scriptedUpsert()) //
|
.scriptedUpsert(queryUpdateRequest.scriptedUpsert()) //
|
||||||
.docAsUpsert(queryUpdateRequest.docAsUpsert());
|
.docAsUpsert(queryUpdateRequest.docAsUpsert()) //
|
||||||
|
.fetchSource(queryUpdateRequest.fetchSource());
|
||||||
|
|
||||||
if (query.DoUpsert()) {
|
if (query.DoUpsert()) {
|
||||||
updateRequest.docAsUpsert(true);
|
updateRequest.docAsUpsert(true);
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.ElasticsearchStatusException;
|
|||||||
import org.elasticsearch.action.index.IndexRequest;
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
@ -55,6 +56,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
|||||||
* @author Sascha Woo
|
* @author Sascha Woo
|
||||||
* @author Don Wellington
|
* @author Don Wellington
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
|
* @author Massimiliano Poggi
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class })
|
||||||
@ -100,6 +102,31 @@ public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
|||||||
assertThat(request.upsertRequest()).isNotNull();
|
assertThat(request.upsertRequest()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAES-693
|
||||||
|
public void shouldReturnSourceWhenRequested() throws IOException {
|
||||||
|
// given
|
||||||
|
Map<String, Object> doc = new HashMap<>();
|
||||||
|
doc.put("id", "1");
|
||||||
|
doc.put("message", "test");
|
||||||
|
|
||||||
|
UpdateRequest updateRequest = new UpdateRequest()
|
||||||
|
.doc(doc)
|
||||||
|
.fetchSource(FetchSourceContext.FETCH_SOURCE);
|
||||||
|
|
||||||
|
UpdateQuery updateQuery = new UpdateQueryBuilder() //
|
||||||
|
.withClass(SampleEntity.class) //
|
||||||
|
.withId("1") //
|
||||||
|
.withUpdateRequest(updateRequest).build();
|
||||||
|
|
||||||
|
// when
|
||||||
|
UpdateRequest request = (UpdateRequest) ReflectionTestUtils //
|
||||||
|
.invokeMethod(elasticsearchTemplate, "prepareUpdate", updateQuery);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(request).isNotNull();
|
||||||
|
assertThat(request.fetchSource()).isEqualTo(FetchSourceContext.FETCH_SOURCE);
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@Document(indexName = "test-index-sample-core-rest-template", type = "test-type", shards = 1, replicas = 0,
|
@Document(indexName = "test-index-sample-core-rest-template", type = "test-type", shards = 1, replicas = 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user