Home > Enterprise >  How to get source in response from ES while using UpdateQuery - Spring Data ElasticSearch
How to get source in response from ES while using UpdateQuery - Spring Data ElasticSearch

Time:11-08

I am using spring-data-elasticsearch to update a document in ES. How do I get the updated source back from ES as part of the response? Below is the code. The UpdateResponse seems to have only the status codes.

UpdateQuery updateQuery=UpdateQuery.builder(esId).withFetchSource(true).withScript(updateScript).build();
UpdateResponse updateResponse = elasticsearchTemplate.update(updateQuery, IndexCoordinates.of(indexName));

I am looking for equivalent of below ES API

GetResult result = updateResponse.getGetResult(); 
if (result.isExists()) {
    String sourceAsString = result.sourceAsString(); 
    Map<String, Object> sourceAsMap = result.sourceAsMap(); 
    byte[] sourceAsBytes = result.source();

thnx

CodePudding user response:

From the source code of org.springframework.data.elasticsearch.core.query.UpdateResponse:

/**
 * Response data from an update request ({@link UpdateQuery}). Currently contains only the result status value from
 * Elasticsearch. Should be extended if further information is needed.
 */

Nobody up to now needed and requested this. Feel free to create an issue for this at https://github.com/spring-projects/spring-data-elasticsearch/issues

  • Related