Defining <uniqueKey> as a "long" or "int" type throws an error on startup

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竞价排名的文章。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值