mstein / elasticsearch-grails-plugin

ElasticSearch grails plugin
Based on Graeme Rocher initial stub. Note that it is still in early stage.
Other
62 stars 164 forks source link

Index transient fields #17

Open jordim opened 12 years ago

jordim commented 12 years ago

Is that possible?

msmolyak commented 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?

thch0014 commented 11 years ago

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 propTransients = convertToSet(transientsProp);

if (!propTransients.isEmpty()) { mappableProperties.addAll(propTransients); }

In DeepDomainClassMarshaller.groovy, i changed domainClass.getPersistantProperties to for (GrailsDomainClassProperty prop in domainClass.properties) {

manuelvio commented 11 years ago

I've tried cthoma's fix and it works. Thanks for sharing here!

v1p commented 10 years ago

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{...}