mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 12:02:10 +00:00
DATAES-228 Fix id handling for indexing
When an id is set in the IndexQuery object, use it without requiring an @Document annotation. When it is not, try to resolve it from the object when it has @Document and @Id annotations.
This commit is contained in:
parent
53b587101d
commit
2b60128390
@ -28,6 +28,7 @@ import static org.springframework.util.CollectionUtils.isEmpty;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
@ -102,6 +103,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mason Chan
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Janssen
|
||||
*/
|
||||
|
||||
public class ElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
|
||||
@ -1013,13 +1015,10 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
IndexRequestBuilder indexRequestBuilder = null;
|
||||
|
||||
if (query.getObject() != null) {
|
||||
String entityId = null;
|
||||
if (isDocument(query.getObject().getClass())) {
|
||||
entityId = getPersistentEntityId(query.getObject());
|
||||
}
|
||||
String id = isBlank(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId();
|
||||
// If we have a query id and a document id, do not ask ES to generate one.
|
||||
if (query.getId() != null && entityId != null) {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId());
|
||||
if (id != null) {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type, id);
|
||||
} else {
|
||||
indexRequestBuilder = client.prepareIndex(indexName, type);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user