【问题标题】:Does Solr have an API to read schema.xml?Solr 是否有读取 schema.xml 的 API?
【发布时间】:2011-11-07 00:20:35
【问题描述】:

是否有任何 Solr API 可以读取 Solr schema.xml?

我需要它的原因是 Solr faceting 不向后兼容。如果索引没有定义字段 A,但程序尝试为字段 A 生成分面,则所有分面都会失败。因此,我需要在运行时检查索引中有哪些字段,并动态生成构面。

【问题讨论】:

    标签: solr schema facet


    【解决方案1】:

    实际上,您拥有 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)

    【讨论】:

      【解决方案2】:

      从 Solr 4.2 开始,Schema REST API 允许您通过以下方式获取架构:

      http://localhost:8983/solr/schema
      

      或使用核心名称:

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

      从 Solr 4.4 开始,您还可以修改架构。

      more details on the Solr Wiki page

      【讨论】:

        【解决方案3】:

        另一种方法是使用 LukeRequestHandler。它以Luke 工具为蓝本,用于诊断Lucene Index 的内容。查询 /admin/luke?show=schema 将显示架构。但是,您需要像这样在 solrconfig.xml 中定义它:

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

        LukeRequestHandlerlink的文档

        【讨论】:

          【解决方案4】:

          您可以使用http://localhost:8983/solr/admin/file/?contentType=text/xml;charset=utf-8&amp;file=schema.xml 获取架构

          这是原始 xml,因此必须对其进行解析以获取所需的信息。

          但是,如果您的程序生成了无效的 facet,也许您应该只修复程序而不是尝试解决此问题。

          【讨论】:

          • Dose solr 有 api 读取吗?我注意到用于读取 solrconf.xml 的 api 是可用的。但是我找不到 schema.xml 的那个
          • @Qing Zhang:你的客户端平台是什么?
          • 如何通过 api 读取 solrconf.xml,有 doc 链接吗?我试图找到它,但找不到它。
          猜你喜欢
          • 2012-12-01
          • 1970-01-01
          • 2013-03-01
          • 2023-03-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多