在Solr中索引嵌套文档 [英] Indexing nested documents in Solr

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

问题描述

我已经看到Solr将允许您索引JSON: http://wiki.apache.org/solr/UpdateJSON

I've seen that Solr will allow you to index JSON: http://wiki.apache.org/solr/UpdateJSON

但是,没有一个示例是嵌套的.您可以为这样的索引编制索引吗?如果没有,通常如何处理?

However, none of the examples are nested. Can you index something like this and if not how is it normally handled?

{
  name: 'ben',
  state: 'california',
  country: 'united states',
  companies: [
    {
      name: 'google',
      title: 'software engineer',
    },
    {
      name: 'sherwin-williams',
      title: 'web developer'
    }
  ],
}

推荐答案

有两种方法. json字符串可以显式存储,并在应用程序层中进行序列化处理. Elasticsearch透明地使用此方法.

There are a couple ways to go. A json string can be stored explicitly, with serialization handled in the application layer. Elasticsearch uses this approach transparently.

对于索引,您可以使用命名约定对数据进行展平. Mongodb使用这种语法.

For indexing, you can flatten the data using naming conventions. Mongodb uses such a syntax.

companies.name: ['google', 'sherwin-williams']
companies.title: ['software engineer', 'web developer']

在这种情况下,请注意类似

Note in such a case a query like

<BooleanQuery: +companies.name:google +companies:web developer>

将匹配.如果位置很重要,则必须使用更高级的SpanQuery.

would match. If the position should matter, a more advanced SpanQuery would have to be used.

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

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