2011-08-30 129 views
5

是否有任何solr api來讀取solr schema.xml?我需要它的原因是solr facet不是向後兼容的。如果索引未定義字段A,但程序試圖爲字段A生成構面,則所有構面都將失敗。因此,我需要在運行時檢查索引中的哪些索引字段,並動態生成構面。solr是否有API來讀取solr schema.xml?

回答

3

你可以得到http://localhost:8983/solr/admin/file/?contentType=text/xml;charset=utf-8&file=schema.xml

這是原始的XML架構,因此必須對其進行解析,以獲得您所需要的信息。但是,如果你的程序產生一個無效的方面,也許你應該修復程序,而不是試圖解決這個問題。

+0

劑量Solr的有API來讀它?我注意到讀取solrconf.xml的api是可用的。但是我找不到schema.xml文件 –

+0

@Qing Zhang:你的客戶端平臺是什麼? –

+0

如何通過api讀取solrconf.xml文件的任何鏈接?我試圖找到,但無法找到它。 – Krunal

3

一種替代方法是使用LukeRequestHandler。它是模仿Luke工具,用於診斷Lucene索引的內容。查詢/ admin/luke?show = schema將向您顯示架構。但是,您將需要solrconfig.xml中定義它像這樣:LukeRequestHandler的

<requestHandler name="/admin/luke" class="org.apache.solr.handler.admin.LukeRequestHandler" /> 

文檔link

3

由於Solr的4.2架構REST API允許你用得到的架構:

http://localhost:8983/solr/schema 

或核心名稱:

http://localhost:8983/solr/mycorename/schema 

由於Solr的4.4你也可以修改你的模式。

more details on the Solr Wiki page

1

其實你擁有該架構的API。 Solr模式API允許使用REST API來獲取有關信息的schema.xml

在Solr的4.2和4.3,它只允許GET(只讀)訪問,但在 Solr的4.4,新領域和新copyField指令可能會添加到架構中。未來的Solr的版本將擴展這一功能,讓更多的模式 元素進行更新

API入口點

/collection/schema: retrieve the entire schema 
/collection/schema/fields: retrieve information about all defined fields, or create new  fields with optional copyField directives 
/collection/schema/fields/name: retrieve information about a named field, or create a new named field with optional copyField directives 
/collection/schema/dynamicfields: retrieve information about dynamic field rules 
/collection/schema/dynamicfields/name: retrieve information about a named dynamic rule 
/collection/schema/fieldtypes: retrieve information about field types 
/collection/schema/fieldtypes/name: retrieve information about a named field type 
/collection/schema/copyfields: retrieve information about copy fields, or create new copyField directives 
/collection/schema/name: retrieve the schema name 
/collection/schema/version: retrieve the schema version 
/collection/schema/uniquekey: retrieve the defined uniqueKey 
/collection/schema/similarity: retrieve the global similarity definition 
/collection/schema/solrqueryparser/defaultoperator: retrieve the default operator 

例子

輸入 獲取所有字段的列表。

​​

輸入 獲取JSON整個模式。

curl http://localhost:8983/solr/collection1/schema?wt=json 

更多信息here: apache-solr-ref-guide-4.5.pdf(搜索模式API)