Open jordim opened 12 years ago
I am also interested in being able to store transient domain object fields in Elastic Search. My initial attempts were not successful - the fields are not added to the index. Is there a limitation on adding transitive fields to the index?
Here is an example how i used transient props in grails-elasticsearch plugin: Domain class: static searchable = { root false compositeName index: 'not_analyzed' transientsProp = ['compositeName'] except = ['userRoleList','userProfile','creationSource'] }
public String getCompositeName(){ return this.firstname + " " + this.lastname } static transients = ['compositeName']
Added private Object transientsProp; to SearchableDomainClassMapper.java
I am using the searchable closure, so i adapted the method buildMappingFromOnlyExcept
Added:
Set
if (!propTransients.isEmpty()) { mappableProperties.addAll(propTransients); }
In DeepDomainClassMarshaller.groovy, i changed domainClass.getPersistantProperties to for (GrailsDomainClassProperty prop in domainClass.properties) {
I've tried cthoma's fix and it works. Thanks for sharing here!
There's a problem, if the transient property is trying to access id of current object, it's throwing an AssertionFailure in buildJSON() method in JSONDomainFactory. @thch0014 - any ideas if you might have faced the same ?
UPDATE: Resolved it by wrapping innards of transient getter method, inside a withNewSession{...}
Is that possible?