用于嵌套文档索引和搜索的Solr管理模式

时间:2020-09-03 08:18:40

标签: solr

关于在Solr中创建嵌套文档索引的架构,我已经读了很多,但是我找不到一种清晰的方法。 我希望以以下嵌套方式为文档建立索引:

[
 { 
     id : book1,
     name:abby,
     brand : humour,
  _childDocuments_ : [
    { 
      department:Book,
      category:Fiction
    }
    ,
    { 
      department:Library,
      category:Facts
    }
  ]
 }
]

我在这里阅读了文档:https://lucene.apache.org/solr/guide/8_0/indexing-nested-documents.html#:~:text=By%20way%20of%20example%2C%20nested,other%20variations%20as%20child%20documents.,它建议在我们的模式文件中包含<field name="_root_" type="string" indexed="true" stored="false" docValues="false" /><fieldType name="_nest_path_" class="solr.NestPathField" /> <field name="_nest_path_" type="nest_path" />

完成这两个步骤之后,并使用curl命令提取文档:

curl -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/itemsetNested/update/json/docs' --data-binary '
 { 
     id : book1,
     name:abby,
     brand : humour,
  _childDocuments_ : [
    { 
      department:Book,
      category:Fiction
    }
    ,
    { 
      department:Library,
      category:Facts
    }
  ]
 }'

我对q=*:*运行了solr查询,并得到了

response":{"numFound":1,"start":0,"docs":[
  {
    "id":"book1",
    "name":"abby",
    "brand":"humour",
    "_childDocuments_.department":[Book,Library],
    "_childDocuments_.category":[Fiction,Facts],
    "_version_":1676785250207793152}]}

根本不维护嵌套结构。 有人可以在索引此文档之前提供所需的schema.xml以便具有嵌套结构吗?

我的托管模式文件中的摘录:

  <field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
  <fieldType name="_nest_path_" class="solr.NestPathField" />
  <field name="_nest_path_" type="_nest_path_" />
  <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    
  <field name="_version_" type="plong" indexed="false" stored="false"/>
  <field name="department" type="text_singular" indexed="true" stored="true" required="false"/> 
  <field name="category" type="text_singular" indexed="true" stored="true" required="false"/>
  

  <field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>
  <field name="name" type="string" indexed="true" stored="true" required="false"/> 
  <field name="brand" stored="true" indexed="true" type="text_simple" multiValued="false"/>

0 个答案:

没有答案
相关问题