在 Cassandra 中存储无模式复杂 json 对象

Storing schema-less complex json object in Cassandra

我有一个无模式的 json 对象,我希望使用 spring-cassandra 将其存储在 Cassandra DB 中。我了解到 Cassandra 支持 Map 类型,但 Cassandra 不接受 Map<String, Object> 作为数据模型。

我需要查询 json 的字段,因此将其存储为 blob 是不可能的。无论如何我可以做到这一点吗?

PS:我查看了 Storing JSON object in CASSANDRA,答案似乎不适用于我的用例,因为我的 json 可能非常复杂。

你看过 UDT(用户定义类型)了吗?

您可以这样定义一个 UDT:

CREATE TYPE my_json(
   property1 text,
   property2 int,
   property3 map<text, text>,
   property4 map<int, another_json_type>,
   ...
)

然后在 Java 中使用 Map<String, UserType>

注意:UserType 来自 Java 驱动程序:https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/UserType.java

您无法创建用户类型 n Java,您只能从 table 的元数据中获取它,请参见:https://github.com/datastax/java-driver/blob/3.0/driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java#L62-L81

1) 我的一个解决方案是,首先集成 solr 搜索和索引table。

2) 稍后写一个solr分析器来解析json并在索引的时候放在solr中的各个字段下。

3) 下一步是使用 solr 支持的查询,例如 select * from table where solr_query = "{search expression syntax}"