Skip to content
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

Index transient fields #17

Open
jordim opened this issue Mar 14, 2012 · 4 comments
Open

Index transient fields #17

jordim opened this issue Mar 14, 2012 · 4 comments

Comments

@jordim
Copy link

jordim commented Mar 14, 2012

Is that possible?

@msmolyak
Copy link

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
Copy link

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
Copy link

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

@v1p
Copy link

v1p commented Jun 12, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants