首页 > 解决方案 > 如何在 SOLR 中创建嵌套的 JSON 对象?

问题描述

我在 SOLR 数据库中转储数据。之前我使用的是 Elastic Search,它允许我存储嵌套的 JSON 对象。

在 SOLR 中插入时,有什么方法可以动态创建嵌套的 JSON 值?

我使用 JAVA 作为后端语言。我的代码是:

SolrInputDocument document = new SolrInputDocument();
document.addField("UUID", eventID);
document.addField("eventCategory", eventCategory);
.
.
.
.
document.addField("source", source);

I want something like this: 
{
"UUID":"1",
"source":abcd,
"eventCategory": {
    "event1":"a",
    "event2":"b",
    "event3":"c"
 }
}

标签: elasticsearchsolr

解决方案


Solr 是平面模式文档的集合。您可以向 solr 添加动态字段,但它不支持嵌套的 JSON 对象。

但是您可以使用以下资源中指定的嵌套文档。

https://lucene.apache.org/solr/guide/6_6/uploading-data-with-index-handlers.html

但是查询子文档并不像 ElasticSearch 或 MongoDB 那样简单。


推荐阅读