如何在Solr中检索完整的嵌套文档? [英] How can you retrieve a full nested document in Solr?

查看:673
本文介绍了如何在Solr中检索完整的嵌套文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Solr 4.10.3 实例中,我想使用嵌套结构索引JSON.

In my instance of Solr 4.10.3 I would like to index JSONs with a nested structure.

示例:

{
  "id": "myDoc",
  "title": "myTitle"
  "nestedDoc": {
    "name": "test name"
    "nestedAttribute": {
      "attr1": "attr1Val"
    }
  }
}

我能够通过管理界面正确存储它:

I am able to store it correctly through the admin interface:

/solr/#/mySchema/documents

/solr/#/mySchema/documents

我还可以搜索和检索文档.

and I'm also able to search and retrieve the document.

我面临的问题是,当我从Solr搜索中获取响应文档时,看不到嵌套的属性.我只看到:

The problem I'm facing is that when I get the response document from my Solr search, I cannot see the nested attributes. I only see:

{
  "id": "myDoc",
  "title": "myTitle"
}

有没有办法在返回的文档中包含所有嵌套字段?

Is there a way to include ALL the nested fields in the returned documents?

我尝试使用:"fl = [child parentFilter = title:myTitle]",但无法正常工作(ChildDocTransformerFactory来自:

I tried with : "fl=[child parentFilter=title:myTitle]" but it's not working (ChildDocTransformerFactory from:https://cwiki.apache.org/confluence/display/solr/Transforming+Result+Documents). Is that the right way to do it or is there any other way?

我正在使用: Solr 4.10.3 !!!!!!

推荐答案

要获取所有嵌套结构,您确实需要使用

To get returned all the nested structure, you indeed need to use ChildDocTransformerFactor. However, you first need to properly index your documents.

如果您只是按原样传递了结构,Solr会将它们索引为单独的文档,并且不会知道它们实际上已连接.如果要能够正确查询嵌套文档,则必须按照脚本.不幸的是,包括最新的Solr 6.0在内,在索引和返回嵌套文档结构方面还没有一个很好且顺畅的解决方案,因此所有事情都是通过变通办法"完成的.

If you just passed your structure as it is, Solr will index them as separate documents and won't know that they're actually connected. If you want to be able to correctly query nested documents, you'll have to pre-process your data structure as described in this post or try using (modifying as needed) a pre-processing script. Unfortunately, including the latest Solr 6.0, there's no nice and smooth solution on indexing and returning nested document structures, so everything is done through "workarounds".

尤其是在您的情况下,您需要将文档结构转换为此:

Particularly in your case, you'll need to transform your document structure into this:

{
  "type": "parentDoc", 
  "id": "myDoc",
  "title": "myTitle"
  "_childDocuments_": [ 
  {
     "type": "nestedDoc",
     "name": "test name",
     "_childDocuments_" :[
     { 
      "type": "nestedAttribute"
       "attr1": "attr1Val"
     }]
   }]    
} 

然后,下面的ChildDocTransformerFactor查询将返回您的所有子文档(顺便说一句,尽管它说自Solr 4.9起就可以使用,但实际上我只在Solr 5.3中看到过……所以您需要测试):

Then, the following ChildDocTransformerFactor query will return you all subdocuments (btw, although it says it's available since Solr 4.9, I've actually only seen it in Solr 5.3... so you need to test):

q=title:myTitle&fl=*,[child parentFilter=type:parentDoc limit=50]

注意,尽管它返回了所有嵌套的文档,但是返回的文档结构将是 flattend (alas!),即,您将得到:

Note, although it returns all nested documents, the returned document structure will be flattend (alas!), i.e., you'll get:

{
  "type": "parentDoc", 
  "id": "myDoc",
  "title": "myTitle"
  "_childDocuments_": [ 
  {
     "type": "nestedDoc",
     "name": "test name"
  },   
  { 
      "type": "nestedAttribute"
       "attr1": "attr1Val"
  }]    
} 

可能不是真的您所期望的,但是...这是不幸的Solr行为,将在最近的将来版本中修复.

Probably, not really what you've expected but... this is the unfortunate Solr's behavior that will be fixed in a nearest future release.

这篇关于如何在Solr中检索完整的嵌套文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆