【问题标题】:How to retrieve json in original nested form in apache solr?如何在 apache solr 中以原始嵌套形式检索 json?
【发布时间】:2025-12-18 10:00:02
【问题描述】:

我正在使用 apache solr 进行 文本搜索。我有nested document structure。这是one.json 文件:

{
"id": "1",
"info": {
       "first_name": "John",
       "last_name": "Doe",
       "gender": "male"
        }
}

我创建了一个 solr 核心并在其中发布了 one.json。Solr indexed and flattened the above document's nested structure ,我想以以下形式更好地索引:

{
    "id":["1"],
    "info.first_name":["John"],
    "info.last_name":["Doe"],
    "info.gender":["male"]
}

现在,当我进行搜索查询时,result is in flattened form

对于我的要求,I want the response json in original nested form

如何在 Solr 中实现这一点?搜索时有some tool that I can use with Solr to get the original nested json吗?

加法:

我正在使用solr 6.3.0。当我将 json 文件添加到核心时,solr automatically indexed the json filemanaged-schema.xml 是由 solr 生成的。

这是定义字段的portion of managed-schema.xml

<field name="_root_" type="string" docValues="false" indexed="true" stored="false"/>
  <field name="_text_" type="text_general" multiValued="true" indexed="true" stored="false"/>
  <field name="_version_" type="long" indexed="false" stored="false"/>
  <field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
  <field name="info.first_name" type="strings"/>
  <field name="info.gender" type="strings"/>
  <field name="info.last_name" type="strings"/>

【问题讨论】:

  • 能否向我们展示已定义字段的 schema.xml?
  • @Oyeme 我已经在描述中添加了managed-schema.xml 的内容。我已经添加了定义字段的那些部分。这些 managed-schema.xml 的所有内容都是 solr 在我将 json 添加到 core 时自己生成的。

标签: solr full-text-search


【解决方案1】:

这可以通过the Reference Guide section on processing custom JSON 中描述的srcField 参数实现。请注意嵌套文档将被索引为单个文档的限制。

techproduct 示例配置了 srcField,如果您想使用随附的架构对其进行测试。

【讨论】: