Solr中嵌套文档的索引
我已经看到Solr将允许您索引JSON: 但是,没有一个示例是嵌套的。你能为这样的东西编制索引吗?如果不能,它通常是如何处理的Solr中嵌套文档的索引,solr,lucene,Solr,Lucene,我已经看到Solr将允许您索引JSON: 但是,没有一个示例是嵌套的。你能为这样的东西编制索引吗?如果不能,它通常是如何处理的 { name: 'ben', state: 'california', country: 'united states', companies: [ { name: 'google', title: 'software engineer', }, { name: 'sherwin-willia
{
name: 'ben',
state: 'california',
country: 'united states',
companies: [
{
name: 'google',
title: 'software engineer',
},
{
name: 'sherwin-williams',
title: 'web developer'
}
],
}
有两条路要走。json字符串可以显式存储,并在应用程序层处理序列化。Elasticsearch透明地使用这种方法 对于索引,可以使用命名约定展平数据。Mongodb使用这种语法
companies.name: ['google', 'sherwin-williams']
companies.title: ['software engineer', 'web developer']
在这种情况下,请注意如下查询
<BooleanQuery: +companies.name:google +companies:web developer>
会匹配的。如果这个职位很重要,就必须使用更高级的span查询。我也有同样的问题。我们想用数组和映射在solr中索引复杂的json文档(比您发布的示例复杂得多) 最后,我修改了JsonLoader类以接受这种文档。它所做的是,将json结构展平,并允许对字段进行索引,并保留原始json结构[company]。最后,它支持深度嵌套 您可以在上找到带有一些解释的源代码 在您的示例中,它将[根据您如何配置字段]存储/索引以下结构
name: 'ben',
state: 'california',
country: 'united states',
companies.0.name: 'google',
companies.0.title: 'software engineer',
companies.1.name: 'sherwin-williams',
companies.1.title: 'web developer'
companies_json:[
{
name: 'google',
title: 'software engineer',
},
{
name: 'sherwin-williams',
title: 'web developer'
}
]
M.嵌套的JSON可以在solr中的子文档的帮助下编制索引。我们可以利用来查询它
请参阅在最新的Lucene版本中,现在有了嵌套:Lucene通过称为索引时间连接的功能,从3.4版开始支持嵌套文档。然而,我找不到任何关于如何创建嵌套文档的教程或简单示例。