【发布时间】:2011-11-07 00:20:35
【问题描述】:
是否有任何 Solr API 可以读取 Solr schema.xml?
我需要它的原因是 Solr faceting 不向后兼容。如果索引没有定义字段 A,但程序尝试为字段 A 生成分面,则所有分面都会失败。因此,我需要在运行时检查索引中有哪些字段,并动态生成构面。
【问题讨论】:
是否有任何 Solr API 可以读取 Solr schema.xml?
我需要它的原因是 Solr faceting 不向后兼容。如果索引没有定义字段 A,但程序尝试为字段 A 生成分面,则所有分面都会失败。因此,我需要在运行时检查索引中有哪些字段,并动态生成构面。
【问题讨论】:
实际上,您拥有 Schema 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
示例
输入 获取所有字段的列表。
curl http://localhost:8983/solr/collection1/schema/fields?wt=json
输入 以 JSON 格式获取整个架构。
curl http://localhost:8983/solr/collection1/schema?wt=json
更多信息here: apache-solr-ref-guide-4.5.pdf(搜索 Schema API)
【讨论】:
从 Solr 4.2 开始,Schema REST API 允许您通过以下方式获取架构:
http://localhost:8983/solr/schema
或使用核心名称:
http://localhost:8983/solr/mycorename/schema
从 Solr 4.4 开始,您还可以修改架构。
【讨论】:
您可以使用http://localhost:8983/solr/admin/file/?contentType=text/xml;charset=utf-8&file=schema.xml 获取架构
这是原始 xml,因此必须对其进行解析以获取所需的信息。
但是,如果您的程序生成了无效的 facet,也许您应该只修复程序而不是尝试解决此问题。
【讨论】: