Skip to content

Don't update indexed object if it is no persistent entity [DATAES-229] #803

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jeff Eltgroth opened DATAES-229 and commented

I am writing a Spring-batch job that uses ElasticsearchTemplate.index(IndexQuery) to load items into an index. I specify the index and type names on the IndexQuery, so I would like to avoid adding @Document to my entity class. If I set the IndexQuery object to a bean without the @Document annotation, ElasticsearchTemplate.setPersistentEntityId throws an assertion exception that the object does not contain the @Document annotation. The operation to store the item to Elasticsearch was completely successful as I can query for the record after the index call.

In the case of index, would it be possible to add a check for the @Document annotation before calling setPersistentEntityId? Possibly:

@Override
public String index(IndexQuery query) {
	String documentId = prepareIndex(query).execute().actionGet().getId();
	// We should call this because we are not going through a mapper.
	if (query.getObject() != null && query.getObject().getClass().isAnnotationPresent(Document.class)) {
		setPersistentEntityId(query.getObject(), documentId);
	}
	return documentId;
}

No further details from DATAES-229

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions