Elastic search+grails throwing NPE

2019-09-13 03:44发布

This is in followup to this question Grails elasticsearch plugin with "text" mapping

I followed the steps given in the answer and now following NPE is thrown. Also, if I open the lucene index using Luke then I do not see any documents in it..

Though while restarting the app server gives me following debug messages

2013-06-03 16:20:49,364 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - Retrieved index settings
2013-06-03 16:20:49,365 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - Installing mappings...
2013-06-03 16:20:49,370 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - Index com.ecw.wellness does not exists, initiating creation...
2013-06-03 16:20:49,370 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - Waiting at least yellow status on com.ecw.wellness ...
2013-06-03 16:21:19,869 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - {com_ecw_wellness_answer={properties={answer={type=string, include_in_all=true, term_vector=with_positions_offsets}, votes={type=object}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, question={type=object}}}}
2013-06-03 16:21:19,869 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - [com_ecw_wellness_answer] => {com_ecw_wellness_answer={properties={answer={type=string, include_in_all=true, term_vector=with_positions_offsets}, votes={type=object}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, question={type=object}}}}
2013-06-03 16:21:19,925 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - [com_ecw_wellness_comment] => {com_ecw_wellness_comment={properties={post={type=object}, vote={type=integer, include_in_all=true}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, comment={type=string, include_in_all=true, term_vector=with_positions_offsets}}}}
2013-06-03 16:21:19,977 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - [com_ecw_wellness_post] => {com_ecw_wellness_post={properties={tags={type=object}, body={type=string, include_in_all=true, term_vector=with_positions_offsets}, title={type=string, include_in_all=true, term_vector=with_positions_offsets}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, comments={properties={post={type=object}, vote={type=integer, include_in_all=true}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, comment={type=string, include_in_all=true, term_vector=with_positions_offsets}, id={type=long, index=not_analyzed, include_in_all=false}, class={type=string, index=no, include_in_all=false}, ref={type=string, index=no, include_in_all=false}}, type=object}}}}
2013-06-03 16:21:20,005 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - [com_ecw_wellness_question] => {com_ecw_wellness_question={properties={tags={type=object}, title={type=string, include_in_all=true, term_vector=with_positions_offsets}, answers={type=object}, dateCreated={type=date, include_in_all=true}, lastUpdated={type=date, include_in_all=true}, question={type=string, include_in_all=true, term_vector=with_positions_offsets}}}}
2013-06-03 16:21:20,010 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - Cluster status: GREEN

Following is the NPE stacktrace. Domain classes are given in the original question.

| Error 2013-06-03 16:17:00,891 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /wellness/search - parameters:
q: smoking
Stacktrace follows:
Message: null
    Line | Method
->>  181 | unmarshallProperty in org.grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     73 | buildResults       in     ''
|    435 | doCall . . . . . . in org.grails.plugins.elasticsearch.ElasticSearchService$_doSearch_closure7
|     14 | withElasticSearch  in org.grails.plugins.elasticsearch.ElasticSearchHelper
|    426 | doSearch . . . . . in org.grails.plugins.elasticsearch.ElasticSearchService
|     86 | search             in     ''
|      6 | index . . . . . .  in com.ecw.wellness.SearchController
|    195 | doFilter           in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker          in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                in java.lang.Thread

If I run the project in transport mode with following info then I am getting "No node available error"

elasticSearch.client.mode = 'transport'
        elasticSearch.client.hosts = [
            [host:'localhost', port:9300]
     ]
    }

If I added following in post

 static searchable = {
    except = ["user"]
comments reference:true

}

and this in comment

    static searchable = {
    except = ["user"]
    post reference:true
}

Then I am getting following SO exception.. And if I do it only in post class then I get Property Comment.post is not mapped as [component], but broken search hit found. error on runtime

    ERROR errors.GrailsExceptionResolver  - StackOverflowError occurred when processing request: [GET] /wellness/search - parameters:
q: smoking
Stacktrace follows:
Message: Executing action [index] of controller [com.ecw.wellness.SearchController]  caused exception: Runtime error executing action
    Line | Method
->>  195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by ControllerExecutionException: Runtime error executing action
->>  195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by InvocationTargetException: null
->>  195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by StackOverflowError: null
->>  354 | findClass in java.net.URLClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    171 | oldFindClass in org.codehaus.groovy.tools.RootLoader
|    143 | loadClass in     ''
|    356 | loadClass in java.lang.ClassLoader
|    263 | unmarshallDomain in org.grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller
|    256 | unmarshallReference in     ''
|    178 | unmarshallProperty in     ''
|    204 | unmarshallProperty in     ''
|    268 | unmarshallDomain in     ''
|    256 | unmarshallReference in     ''
|    178 | unmarshallProperty in     ''
|    268 | unmarshallDomain in     ''
|    256 | unmarshallReference in     ''
|    178 | unmarshallProperty in     ''
|    204 | unmarshallProperty in     ''
|    268 | unmarshallDomain in     ''
|    256 | unmarshallReference in     ''
|    178 | unmarshallProperty in     ''
|    268 | unmarshallDomain in     ''
|    256 | unmarshallReference in     ''
|    178 | unmarshallProperty in     ''
|    204 | unmarshallProperty in     ''

1条回答
可以哭但决不认输i
2楼-- · 2019-09-13 04:34

Add elasticSearch.unmarshallComponents = true in your Config.groovy. A default value is supposed to be provided in the grails-app/conf/DefaultElasticSearch.groovy file of the plugin, but somehow it is not loaded properly.

Also see issue#62 on the Github repository

Transport mode needs a standalone ES instance to be running outside the grails application.


Edit: About this issue:

Property Comment.post is not mapped as [component], but broken search hit found.

You need to map in the searchable closure your associations as either a searchable component or reference. The plugin documentation states that searchable references are used by default, but it is somehow not true anymore and the doc is a bit outdated.

The default to searchable reference was removed in a previous version for a reason that I can't recall at the moment, so perhaps a default behavior will be restored in a future version...

Example below:

class Comment {
    Post post
    static belongsTo = [post:Post]

    static searchable = {
            post component:true
    }
}

The documentation explaining the difference between the 2 behaviors

查看更多
登录 后发表回答