SolrCloud 8.4嵌套文档索引查询问题及Schema配置需求
SolrCloud 8.4 嵌套文档基础Schema配置(JSON格式)
以下是适配Solr官方嵌套文档示例数据的基础JSON Schema配置,包含嵌套文档必需的核心字段及常见业务字段定义:
{ "schema": { "name": "nested_docs_schema", "version": 1.6, "uniqueKey": "id", "fields": [ { "name": "id", "type": "string", "stored": true, "required": true }, { "name": "_root_", "type": "string", "stored": false, "indexed": true }, { "name": "title", "type": "text_general", "stored": true, "indexed": true }, { "name": "content", "type": "text_general", "stored": true, "indexed": true }, { "name": "author", "type": "string", "stored": true, "indexed": true }, { "name": "child_docs", "type": "child", "stored": true, "indexed": true, "docValues": false }, { "name": "type", "type": "string", "stored": true, "indexed": true, "multiValued": false } ], "copyFields": [], "dynamicFields": [ { "name": "*_s", "type": "string", "stored": true, "indexed": true }, { "name": "*_t", "type": "text_general", "stored": true, "indexed": true } ] } }
关键配置说明
_root_:必填字段,用于维护父文档与子文档的层级关联,Solr会自动填充该字段值为父文档的idchild_docs:child类型字段,用于存储嵌套的子文档集合type字段:用于区分父/子文档类型(比如父文档标记为article,子文档标记为comment),方便查询时过滤
可选XML格式Schema配置
如果需要XML格式,以下是对应配置:
<?xml version="1.0" encoding="UTF-8"?> <schema name="nested_docs_schema" version="1.6"> <uniqueKey>id</uniqueKey> <fields> <field name="id" type="string" stored="true" required="true"/> <field name="_root_" type="string" stored="false" indexed="true"/> <field name="title" type="text_general" stored="true" indexed="true"/> <field name="content" type="text_general" stored="true" indexed="true"/> <field name="author" type="string" stored="true" indexed="true"/> <field name="child_docs" type="child" stored="true" indexed="true" docValues="false"/> <field name="type" type="string" stored="true" indexed="true" multiValued="false"/> <!-- 动态字段 --> <dynamicField name="*_s" type="string" stored="true" indexed="true"/> <dynamicField name="*_t" type="text_general" stored="true" indexed="true"/> </fields> <copyField source="*" dest="_text_"/> </schema>
索引示例数据参考
你可以用以下格式提交嵌套文档数据(适配上述Schema):
[ { "id": "article_1", "type": "article", "title": "Solr嵌套文档入门", "content": "本文介绍Solr嵌套文档的使用方法", "author": "Solr官方", "child_docs": [ { "id": "comment_1", "type": "comment", "content": "这个教程很有用", "author": "用户A" }, { "id": "comment_2", "type": "comment", "content": "终于搞懂嵌套文档了", "author": "用户B" } ] } ]
基础查询示例
- 查询包含特定子文档内容的父文档:
q={!child of='type:article'}content:有用 - 查询所有子文档:
q=type:comment&fl=id,author,content
内容的提问来源于stack exchange,提问作者Pedro Gomes
相关产品推荐
相关产品推荐

