弹性搜索+ grails抛出NPE [英] Elastic search+grails throwing NPE

查看:226
本文介绍了弹性搜索+ grails抛出NPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是跟随这个问题
Grails弹性搜索插件与文本"映射



我按照答案中给出的步骤,现在在NPE被抛出之后。另外,如果我使用Luke打开lucene索引,那么我看不到任何文件。



虽然重新启动应用服务器时给我以下调试消息

  2013-06-03 16:20:49,364 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator  - 检索到的索引设置
2013-06-03 16:20:49,365 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator - 安装映射...
2013-06-03 16:20:49,370 [localhost-startStop-1] DEBUG映射.SearchableClassMappingConfigurator - 索引com.ecw.wellness不存在,启动创建...
2013-06-03 16:20:49,370 [localhost-startStop-1] DEBUG mapping.SearchableClassMappingConfigurator - 至少等待黄色状态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_offse ts},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 = 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 - 群集状态:GREEN

以下是NPE堆栈跟踪。域名在原始问题中给出。

 错误2013-06-03 16:17:00,891 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - 处理请求时发生NullPointerException:[GET] / wellness / search  - 参数:
q:smoking
Stacktrace如下:
消息:null
Line |方法
- >> 181 | unmarshallProperty在org.grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 73 |
|中的buildResults 435 | doCall。 。 。 。 。 。在org.grails.plugins.elasticsearch.ElasticSearchService $ _doSearch_closure7
| 14 | withElasticSearch in org.grails.plugins.elasticsearch.ElasticSearchHelper
| 426 | doSearch。 。 。 。 。在org.grails.plugins.elasticsearch.ElasticSearchService
|中86 |搜索''
| 6 |指数。 。 。 。 。在com.ecw.wellness.SearchController
| 195 | doFilter在grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter。 。 。 。 。在grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker在java.util.concurrent.ThreadPoolExecutor
|中603 |跑 。 。 。 。 。 。 。在java.util.concurrent.ThreadPoolExecutor $ Worker
^ 722 |运行在java.lang.Thread

如果我以传输模式运行项目,具有以下信息,那么我获得无节点可用错误

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

如果我在帖子中添加了以下内容

  static searchable = {
except = [user]
评论参考:true

}

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

然后我得到以下SO异常..如果我只在post class中我得到属性Comment.post没有被映射为[组件],但找到破损的搜索命中。运行时错误

  ERROR errors.Grail sExceptionResolver  - 处理请求时发生StackOverflowError:[GET] / wellness / search  - 参数:
q:smoking
堆栈跟踪如下:
消息:执行控制器的[index] [com.ecw.wellness .SearchController]引起异常:运行时错误执行动作
Line |方法
- >> 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter在grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker在java.util.concurrent.ThreadPoolExecutor
|中603 |运行在java.util.concurrent.ThreadPoolExecutor $ Worker
^ 722 |跑 。 。 。在java.lang.Thread
由ControllerExecutionException引起:运行时错误执行动作
- >> 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter在grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker在java.util.concurrent.ThreadPoolExecutor
|中603 |运行在java.util.concurrent.ThreadPoolExecutor $ Worker
^ 722 |跑 。 。 。在java.lang.Thread中
由InvocationTargetException引起:null
- >> 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter在grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker在java.util.concurrent.ThreadPoolExecutor
|中603 |运行在java.util.concurrent.ThreadPoolExecutor $ Worker
^ 722 |跑 。 。 。在java.lang.Thread中
由StackOverflowError引起:null
- >> 354 | java.net.URLClassLoader中的findClass
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 171 | oldFindClass在org.codehaus.groovy.tools.RootLoader
|中143 | '
|中的loadClass 356 | java.lang.ClassLoader中的loadClass
| 263 | unmarshallDomain在org.grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller
| 256 | ''
|中的unmarshallReference 178 | '
|中的unmarshallProperty 204 | '
|中的unmarshallProperty 268 | '
|中的unmarshallDomain 256 | ''
|中的unmarshallReference 178 | '
|中的unmarshallProperty 268 | '
|中的unmarshallDomain 256 | ''
|中的unmarshallReference 178 | '
|中的unmarshallProperty 204 | '
|中的unmarshallProperty 268 | '
|中的unmarshallDomain 256 | ''
|中的unmarshallReference 178 | '
|中的unmarshallProperty 268 | '
|中的unmarshallDomain 256 | ''
|中的unmarshallReference 178 | '
|中的unmarshallProperty 204 | unmarshallProperty在''


解决方案

添加 / code>中的
默认值应该在插件的 grails-app / conf / DefaultElasticSearch.groovy 文件中提供,但不知何故未正确加载。 / p>

另请参阅问题#62在Github存储库中



传输模式需要一个独立的ES实例才能在grails应用程序之外运行。






编辑
关于此问题:


属性Comment.post没有映射为[component],但找不到搜索命中。


您需要在可搜索将您的关联作为可搜索的组件参考关闭。插件文档说明默认情况下使用可搜索的引用,但是它不再是真的,文档有点过时了。



默认的可搜索引用在之前的版本中被删除,原因是我目前无法回忆,所以也许以后会恢复默认行为



下面的示例:

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

static searchable = {
post component:true
}
}

说明两种行为之间差异的文档


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     ''

解决方案

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

这篇关于弹性搜索+ grails抛出NPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆