Search code examples
grailsormnhibernate-mappingunmarshallingelasticsearch-plugin

Unmarshalling property fails in Grails and ElasticSearch


I'm using Grails 2.5.0 and ElasticSearch 0.0.4.6! I have the following domain classes:

Class Library {
    --- code omitted ---
    static hasMany = [books:Book]
    static searchable = true
    --- code omitted ---
}

Class Book {
    --- code omitted ---
    static belongsTo = [library:Library]
    static searchable = true
    --- code omitted ---
}

I try to search for books like this:

--- code omitted ---
def events = elasticSearchService.search(
            {
                query_string(fields: ["Name"],
                        query: query)
                suggest : { suggest_mode: 'popular' }
            })

    render events as JSON

I get the following error:

ERROR unmarshall.DomainClassUnmarshaller - Error unmarshalling property 'library' of Class Book with id 2 Message: Property Book.library is not mapped as [component], but broken search hit found.


Solution

  • You will need to set the 'library' property of Book domain as component.

    In your book domain replace your below code

    static searchable = true

    with

    static searchable = { library component: true }

    See elastic plugin document for more details