feliperazeek / playframework-elasticsearch

Integrate Elastic Search in a Play! Framework Application. This module uses JPA events to notify Elastic Search of events of their own. It embeds a running Elastic Search instance for Rapid Development.
http://geeks.aretotally.in/play-framework-module-elastic-search-distributed-searching-with-json-http-rest-or-java
84 stars 43 forks source link

Embedded objects are index as string #10

Closed rschellhorn closed 13 years ago

rschellhorn commented 13 years ago

Suppose the following:

class Institution { public String name; public String type; }

@ElasticSearchable class Education { ... @Embedded Institution institution; }

It would be really nice if the institution name and type are added to the index, preferably by the name institution.name and institution.type. Unfortunately currently one field institution is being created, containing the toString of the embeddable type.

feliperazeek commented 13 years ago

Yea that's a feature I have been planning to add, it's been hard to find time but I will make it happen.

feliperazeek commented 13 years ago

Any help is appreciated of course.

bgooren commented 13 years ago

Working on it!

feliperazeek commented 13 years ago

You are a star dude! Let me know when you want the next release

bgooren commented 13 years ago

I've just created a pull request which adds @ElasticSearchEmbedded.

By default it will embed all properties not annotated with @ElasticSearchIgnore, so as in your example the index for Education would get additional fields "institution.name" and "institution.type". You can also override which fields should be indexed by using the fields attribute on the annotation.

E.g.: @ElasticSearchEmbedded( fields = { "name" } ) will only embed "institution.name" in the index.

Note: for now the code only handles simple embedded properties, which are owned by the entity being indexed. I have looked into handling for embedded fields from an entity which is not owned, byusing something akin to hibernate-search's @ContainedIn, which helps to provide a clue regarding when to update the embedded fields. However, this is quite a hassle to integrate into the current code (been trying to do that for a day).