简体   繁体   English

如何在Solr索引中创建嵌套文档?

[英]How to create nested document in Solr indexing?

I want to create nested document in solr, I am using java/GWT/SolrJ. 我想在solr中创建嵌套文档,我使用的是java / GWT / SolrJ。

Currently I am indexing following fields: 目前我正在索引以下字段:

Items: 项目:
id title desc. id title desc。

1 xyz xyzxyzxyz 1 xyz xyzxyzxyz

2 pqr pqrpqrpqr 2 pqr pqrpqrpqr

3 abc abcabcabc. 3 abc abcabcabc。

But now i want to create one more document linked with each document from above ie for id 1 there is one subdocument which contains follwing fields: 但是现在我想创建一个与上面的每个文档链接的文档,即对于id 1,有一个子文档包含以下字段:

Item_User_Details: Item_User_Details:

for item 1 : 对于第1项:

user details 用户详情

1 qweqweqwe 1 qweqweqwe

2 xyzxyzxyz 2 xyzxyzxyz

3 asdasdasd 3 asdasdasd

in this way I want to create for each item id from above table, there is one linked document of item_user_details. 通过这种方式,我想为上表中的每个项目id创建一个item_user_details的链接文档。

How can I do this...? 我怎样才能做到这一点...? Thanks in advance... 提前致谢...

In our schema we've a lot of related tables. 在我们的模式中,我们有很多相关的表。

We decided to flatten all relations into one document. 我们决定将所有关系扁平化为一个文件。 To achieve this we created a custom importer (using SolrJ), which loads each document from the index, adds the related fields and write that document back. 为此,我们创建了一个自定义导入器(使用SolrJ),它从索引中加载每个文档,添加相关字段并将该文档写回。

[edit] [编辑]
We do this in the following way: 我们通过以下方式执行此操作:

  1. export the data in a csv-file for each table (item, item_user_details) 导出每个表的csv文件中的数据(item,item_user_details)
  2. import each csv-file into Solr, starting with the top (item in your case) 将每个csv文件导入Solr,从顶部开始(在您的情况下为项目)
  3. Start an Embedded-Solr server: 启动Embedded-Solr服务器:
    System.setProperty("solr.solr.home", config.getSolrIndexPath()); CoreContainer.Initializer initializer = new CoreContainer.Initializer(); this.coreContainer = initializer.initialize(); this.solr = new EmbeddedSolrServer(this.coreContainer, "");
    Alternatively you can access a remote solr instance: 或者,您可以访问远程solr实例:
    this.solr = new HttpSolrServer("http://[your-url]/solr");
  4. Create a SolrDocument for each line in the file 为文件中的每一行创建一个SolrDocument
  5. add it to the index this.solr.add(ClientUtils.toSolrInputDocument(doc)); 将它添加到索引this.solr.add(ClientUtils.toSolrInputDocument(doc));
  6. Commit this.solr.commit(); 提交this.solr.commit();
  7. Load documents from the index (items) 从索引(项目)加载文档
  8. Idetify relations in the csv-file for item_user_details via the document id (item-id) 通过文档id(item-id)在item_user_details的csv文件中表示关系
  9. Exted the loaded document with the fields from item_user_details 使用item_user_details中的字段释放加载的文档
  10. Commit the Document again 再次提交文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM