DATAES-56 - while specifying index and type at runtime indexing is failing

(this bug was introduced with DATAES-42)
This commit is contained in:
mohsin.husen
2014-02-14 07:43:40 +00:00
parent be1d26eae3
commit 08a6a9b26f
2 changed files with 105 additions and 3 deletions

View File

@@ -547,8 +547,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
IndexRequestBuilder indexRequestBuilder = null;
if (query.getObject() != null) {
String entityId = null;
if (isDocument(query.getObject().getClass())) {
entityId = getPersistentEntityId(query.getObject());
}
// If we have a query id and a document id, do not ask ES to generate one.
String entityId = getPersistentEntityId(query.getObject());
if (query.getId() != null && entityId != null) {
indexRequestBuilder = client.prepareIndex(indexName, type, query.getId());
} else {
@@ -685,4 +688,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
protected ResultsMapper getResultsMapper() {
return resultsMapper;
}
private boolean isDocument(Class clazz) {
return clazz.isAnnotationPresent(Document.class);
}
}