Polishing.

See #2304
This commit is contained in:
Peter-Josef Meisch 2022-09-25 21:43:15 +02:00
parent b038bbe778
commit 8a1d8deb67
No known key found for this signature in database
GPG Key ID: DE108246970C7708
2 changed files with 7 additions and 4 deletions

View File

@ -60,6 +60,7 @@ import org.springframework.data.util.Streamable;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* This class contains methods that are common to different implementations of the {@link ElasticsearchOperations}
@ -468,18 +469,20 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
}
protected <T> UpdateQuery buildUpdateQueryByEntity(T entity) {
Assert.notNull(entity, "entity must not be null");
String id = getEntityId(entity);
Assert.notNull(entity, "entity must have an id that is notnull");
Assert.notNull(id, "entity must have an id that is notnull");
UpdateQuery.Builder updateQueryBuilder = UpdateQuery.builder(id)
.withDocument(elasticsearchConverter.mapObject(entity));
String routing = getEntityRouting(entity);
if (Objects.nonNull(routing)) {
if (StringUtils.hasText(routing)) {
updateQueryBuilder.withRouting(routing);
}
return updateQueryBuilder.build();
}

View File

@ -27,7 +27,6 @@ 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;
/**
@ -297,9 +296,10 @@ public interface DocumentOperations {
/**
* Partially update a document by the given entity.
*
* @param entity the entity to update partially
* @param entity the entity to update partially, must not be {@literal null}.
* @return the update response
* @param <T> the entity type
* @since 5.0
*/
<T> UpdateResponse update(T entity);