1. 程式人生 > >solr 4.3的一些錯誤解決方法

solr 4.3的一些錯誤解決方法

在去年時候學習使用了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””

這時去檢視日誌,顯示資訊

1 Caused by: org.apache.solr.common.SolrException: Error initializing QueryElevationComponent.
2 at org.apache.solr.handler.component.QueryElevationComponent.inform(QueryElevationComponent.java:218)
3 at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:616)
4 at org.apache.solr.core.SolrCore.<init>(SolrCore.java:816)
5 ... 34 more
6 Caused by: java.lang.NumberFormatException: For input string: "MA147LL/A"
7 at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
8 ... 36 more
9 ERROR - 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
10 at org.apache.solr.handler.admin.CoreAdminHandler.handleCreateAction(CoreAdminHandler.java:524)
11 ...
1 ERROR - 2013-05-22 16:48:46.272; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: ERROR: [doc=100946] unknown field 'message'
2 at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:313)
3 at 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.

再次去查詢這個問題,很快找到

編輯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,終於找到一篇提示的文章

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
3 http://wiki.apache.org/solr/QueryElevationComponent
4
5 a search component that enables you to configure the top
6 results for a given query regardless of the normal lucene
7 scoring.
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>

要配置啟用這項元件,需要配置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

1 ERROR - 2013-05-22 17:59:51.107; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: undefined field text
2 at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1211)
3 at org.apache.solr.schema.IndexSchema$SolrQueryAnalyzer.getWrappedAnalyzer(IndexSchema.java:425)
4 at org.apache.lucene.analysis.AnalyzerWrapper.initReader(AnalyzerWrapper.java:81)
5 at 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!