solr 4.3的一些错误解决方法

来源:互联网 发布:淘宝买配件组装电脑 编辑:程序博客网 时间:2024/06/03 06:43

在去年时候学习使用了solr4.0,现在solr版本最新已经到了4.3了,前两天因为工作需要在一台服务器上面新安装solr,但是生产环境是4.0,不过想到是内部测试用的,且主要功能就是写入,删除,搜索,与程序上面没有太多的深入开发,于是还是安装了最新的4.3版本

解压安装启动后,就可以了;这时需要添加collection,添加的collection配置需要与生产环境保持一致,于是复制默认的collection1 的配置信息作为新的collection

复制完成,新的collection events 也添加完成;但是加载时总是报错不能正确加载solrconfig.xml信息,也知道schema.xml等数据肯定是要修改的,schema.xml配置信息修改完成后还是有这样的问题,在往solr写入数据时又再次报错

undefined filed message,但是message字段确实已经配置好了;检查之后再次重启solr,查看刚才的events 直接显示 “There exists no core with name “events””

这时去查看日志,显示信息

1Caused by: org.apache.solr.common.SolrException: Error initializing QueryElevationComponent.
2at org.apache.solr.handler.component.QueryElevationComponent.inform(QueryElevationComponent.java:218)
3at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:616)
4at org.apache.solr.core.SolrCore.<init>(SolrCore.java:816)
5... 34 more
6Caused by: java.lang.NumberFormatException: For input string: "MA147LL/A"
7at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
8... 36 more
9ERROR - 2013-05-22 16:07:06.752; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: Error CREATEing SolrCore'events': Unable to create core: events
10at org.apache.solr.handler.admin.CoreAdminHandler.handleCreateAction(CoreAdminHandler.java:524)
11...

 

1ERROR - 2013-05-22 16:48:46.272; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: ERROR: [doc=100946] unknown field'message'
2at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:313)
3at org.apache.solr.update.AddUpdateCommand.getLuceneDocument(AddUpdateCommand.java:73)

正在排查中是,同事Y看到了,直接把solr 默认的collection1 改名为 events ,再次刷新直接挂了

There are no SolrCores running. Using the Solr Admin UI currently requires at least one SolrCore.

再次去查找这个问题,很快找到

http://stackoverflow.com/questions/13295208/i-unloaded-the-default-solr-collection-by-mistake-from-the-solr-admin-ui

编辑example/solr/solr.xml配置文件

可以看到已经变为

<core name="events" instanceDir="events" />

改为

<core name="collection1" instanceDir="collection1" />

保存,重启solr即可;

分析为什么出现这个问题,events collection的配置是错误的,solr初始化所有collection时跳过了events,而默认的collection1又改为了events则使用的是events目录下的配置信息了,

而这个配置信息又是错误的,所以solr admin 默认为没有 cores 的;修复过程中需要手动去修改配置文件,同事Y打呼用户体验太不友好了,不过我说Solr Admin用户体验很好啊,很早就不支持IE6了

现在又回到了上面的那个错误,org.apache.solr.common.SolrException: Error initializing QueryElevationComponent.

不能初始化,也不能添加events collection core,继续google,终于找到一篇提示的文章

https://coderwall.com/p/kwvxhq

Note that if you have enabled the QueryElevationComponent in solrconfig.xml it requires the schema to have a uniqueKey of typeStrField. It cannot be, for example, an int field.

Otherwise, you will get exception like:

java.lang.NumberFormatException: For input string: "MA147LL/A"

大意就是如果你开启了 QueryElevationComponent 功能,但是schema 的uniqueKey类型又不是 string,则报如下错误

java.lang.NumberFormatException: For input string: "MA147LL/A" 这个不就是我的日志里面的那个错误信息么, 于是编辑example/solr/events/conf/solrconfig.xml配置文件

搜索QueryElevationComponent关键字,可以看到如下,果然有这个信息

1<!-- Query Elevation Component
2 
3http://wiki.apache.org/solr/QueryElevationComponent
4 
5a search component that enables you to configure the top
6resultsfora given query regardless of the normal lucene
7scoring.
8-->
9<searchComponent name="elevator">
10<!-- pick a fieldType to analyze queries -->
11<str name="queryFieldType">string</str>
12<str name="config-file">elevate.xml</str>
13</searchComponent>

http://wiki.apache.org/solr/QueryElevationComponent查看一下,类似于关键字搜索后,一些项的配置置顶显示 比如百度搜索某个关键字时,搜索框下面的推广,广告相关信息总是被置顶显示

要配置启用这项组件,需要配置elevate.xml,同样是位于example/solr/events/conf/目录下

Elevated query results are configured in an external .xml file determined by the config-file argument. An elevate.xml file may look like this:

<elevate> <query text="AAA">  <doc id="A" />  <doc id="B" /> </query> <query text="ipod">  <doc id="A" />  <!-- you can optionally exclude documents from a query result -->  <doc id="B" exclude="true" /> </query></elevate>

For the above configuration, the query “AAA” would first return documents A and B, then whatever normally appears for the same query. For the query “ipod”, it would first return A, and would make sure that B is not in the result set.

Note: The uniqueKey field must currently be of type string for the QueryElevationComponent to operate properly. 这就是答案了,uniquekey必须是string类型;目前我们项目中没有用到这项功能,所以可以选择注释不启用

1<!--
2<searchComponent name="elevator">
3<!-- pick a fieldType to analyze queries -->
4<str name="queryFieldType">string</str>
5<str name="config-file">elevate.xml</str>
6</searchComponent>
7-->

重启之后,没有初始化失败的错误了,再次往solr加入数据又有一个错误信息 undefined field text

1ERROR - 2013-05-22 17:59:51.107; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: undefined field text
2at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1211)
3at org.apache.solr.schema.IndexSchema$SolrQueryAnalyzer.getWrappedAnalyzer(IndexSchema.java:425)
4at org.apache.lucene.analysis.AnalyzerWrapper.initReader(AnalyzerWrapper.java:81)
5at org.apache.lucene.analysis.Analyzer.tokenStream(Analyzer.java:132)

google 得到结果,就是默认字段需要替换的问题,编辑 example/solr/events/conf/solrconfig.xml 检索到text内容

 <lst name="defaults"> <str name="echoParams">explicit</str> <int name="rows">10</int> <str name="df">text</str> </lst>

因为solrconfig.xml等配置文件时从collection1复制过来的,默认的default字段匹配是text,所以目前改为我们项目所用到的字段值message 保存文件,重启solr,写入数据没有问题了,search也正常的有数据内容返回了

版本的不同,配置文件内容也会做一些变动与修改;所以可能需要修改的配置不仅仅只是与项目search有关的内容,还有版本与版本之间,新版本默认启用的模块所需的配置有关;还有一点,多看日志,多用Google!


参考:http://leil.info/archives/solr-4-3%E7%9A%84%E4%B8%80%E4%BA%9B%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/

1 0
原创粉丝点击