-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Don't try to write readonly id property after indexing #2230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
after not writing readonly id back into java object, how could we solve this situation now? To make it clearer, here is the situation we are facing:
in spring-data-elasticsearch 4.4.1, i handled this situation by using
the mapping is:
If the doc in elasticsearch is However, after upgrading to 4.4.3 with changes in this issue, If i delete the So how could we get the same effect like 4.4.1 now? How could we still get Thanks in advanced. |
I think there is an error in your example: After reading The workaround with adding the The real problem is, that the id property is not only used as identifier in Elasticsearch but also is written into the source - not into the mapping. The addition to the mapping you see is done by Elasticsearch when the data is written to the source and there is no mapping for the field. What would be needed here is a possibility to configure Spring Data Elasticsearch to not write the id property into the document (I created #2364). To get the _id back into your realId in the current version, leave the #import org.springframework.data.elasticsearch.core.event.AfterConvertCallback;
@Component
public class EntityAfterConvertCallback implements AfterConvertCallback<Entity> {
@Override
public Entity onAfterConvert(Entity entity, Document document, IndexCoordinates indexCoordinates) {
entity.setRealId(document.getId());
return entity;
}
} This is invoked after the Entity is set up - and is missing the realId; in this callback you then set the document's id (as returned from Elasticsearch) into the realId property. |
Thanks for the quick response. I'll try this workaround, and totally agree what expresses in #2364 |
In
AbstractElasticsearchTemplate.updateIndexedObject()
the following code is used to set the id property of an entity:Here it must be checked as well if the id property is writeable - check reactive part as well
The text was updated successfully, but these errors were encountered: