solr启动时候,报如下异常:
SEVERE: org.apache.solr.common.SolrException
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:600)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:480)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:332)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:216)
at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:161)
at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:96)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.apache.solr.common.SolrException: Error initializing QueryElevationComponent.
at org.apache.solr.handler.component.QueryElevationComponent.inform(QueryElevationComponent.java:202)
at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:527)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:594)
... 32 more
Caused by: java.lang.NumberFormatException: For input string: "MA147LL/A"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at org.apache.solr.schema.TrieField.readableToIndexed(TrieField.java:291)
at org.apache.solr.handler.component.QueryElevationComponent$ElevationObj.<init>(QueryElevationComponent.java:119)
at org.apache.solr.handler.component.QueryElevationComponent.loadElevationMap(QueryElevationComponent.java:264)
at org.apache.solr.handler.component.QueryElevationComponent.inform(QueryElevationComponent.java:186)
... 34 more
我的solr版本是3.6.1。
通过查看异常堆栈 :Caused by: org.apache.solr.common.SolrException: Error initializing QueryElevationComponent.和Caused by: java.lang.NumberFormatException: For input string: "MA147LL/A"
问题定位在初始化QueryElevationComponent组件时失败。在solrconfig.xml文件中找到QueryElevationComponent的配置项:
<searchComponent name="elevator" class="solr.QueryElevationComponent">
<!-- pick a fieldType to analyze queries -->
<str name="queryFieldType">string</str>
<str name="config-file">elevate.xml</str>
</searchComponent>
<!--
A request handler for demonstrating the elevator component
-->
<requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="df">text</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr>
</requestHandler>
从配置文件得知在初始化QueryElevationComponent的时候会去加载conf目录下的elevate.xml文件,所以打开elevate.xml文件看看:
<elevate>
<query text="foo bar">
<doc id="1" />
<doc id="2" />
<doc id="3" />
</query>
<query text="ipod">
<doc id="MA147LL/A" /> <!-- put the actual ipod at the top -->
<doc id="IW-02" exclude="true" /> <!-- exclude this cable -->
</query>
</elevate>
你会发现有一个id="MA147LL/A"和id="IW-02"的配置项,问题就在于id的值为"MA147LL/A"和IW-02,它是string类型,当我们把所<uniqueKey> id 定义为long或int等number类型时,自然会报以上异常。
这是一个solr的bug:https://issues.apache.org/jira/browse/SOLR-2997
有两种解决方案:
(一)将id="MA147LL/A" 改为id="1",将id="IW-02"改为id="2",将其值设为整形。
(一)在solrconfig.xml文件中注释掉以下代码:(QueryElevationComponent组件对于初学者一般上不用,所以可以先注释掉)
<searchComponent name="elevator" class="solr.QueryElevationComponent">
<!-- pick a fieldType to analyze queries -->
<str name="queryFieldType">string</str>
<str name="config-file">elevate.xml</str>
</searchComponent>
<!--
A request handler for demonstrating the elevator component
-->
<requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="df">text</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr>
</requestHandler>
PS: QueryElevationComponent组件用于solr实现竞价排名,接下来会写一篇关于solr竞价排名的文章。