Partial update with Spring Data Elasticsearch repository
<p>I have a document with many fields (some nested) indexed on elasticsearch. For example:</p>

<pre><code>{
  "id" : 1,
  "username" : "...",
  "name" : "...",
  "surname" : "...",
  "address" : "...",
  "age": 42,
  ...
  "bookmarks" : [{...}, {...}],
  "tags" : [{...}, {...}]
}
</code></pre>

<p>Only some filed is mapped in my entity (I don't want to map the entire document):</p>

<pre><code>@Document(indexName = "...", type = "...")
public class User {
  @Id
  private int id;
  private String username;
  private String address;

  // getter/setter methods

}
</code></pre>

<p>In the service class I would like to do a partial update with <a href="https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java" rel="noreferrer">ElasticsearchRepository</a>, without mapping all document's fields in the entity:</p>

<pre><code>public class UserServiceClass {

  @Autowired
  private UserElasticsearchRepository userElasticsearchRepository;

  public void updateAddress(int id, String updatedAddress) {
    User user = userElasticsearchRepository.findOne(id);
    user.setAddress(updatedAddress);
    userElasticsearchRepository.save(user);
  } 
}
</code></pre>

<p>but <strong><em>save</em></strong> method overwrites the entire document:</p>

<pre><code>{
  "id" : 1,
  "username" : "...",
  "address" : "..."
}
</code></pre>

<p>Partial udpdate seems not supported by <a href="https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java" rel="noreferrer">ElasticsearchRepository</a>. So I used <a href="https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java" rel="noreferrer">ElasticsearchTemplate</a>, to make a partial update, for example:</p>

<pre><code>public class UserServiceClass {

  @Autowired
  private UserElasticsearchRepository userElasticsearchRepository;

  @Autowired
  private ElasticsearchTemplate elasticsearchTemplate;

  public void updateAddress(int id, String updatedAddress) {
    User user = userElasticsearchRepository.findOne(id);
    if (user.getUsername().equals("system")) {
      return;
    }

    IndexRequest indexRequest = new IndexRequest();
    indexRequest.source("address", updatedAddress);
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(user.getId()).withClass(User.class).withIndexRequest(indexRequest).build();
    elasticsearchTemplate.update(updateQuery);
  } 
}
</code></pre>

<p>but seems a bit redundant to have two similar references (repository and ElasticsearchTemplate).</p>

<p>Can anyone suggest me a better solution?</p>