2011-08-30 132 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)