是否可以使用集合在 cql 中搜索标签?

Is it possible to search for a tag in cql using a set?

是否可以在 CQL table 中查询与集合中的特定元素完全匹配的项。比如我们可以在下面的table上搜索where tag="music"?

create table if not exists example (
        website text,
        uuid text,
        message text,
        tags set<text>,
        created timestamp,
        primary key ((site), uuid))

可以使用 CONTAINS 运算符搜索集合中的元素(请参阅 documentation). But it will be very slow, so index on collection may help (see docs for syntax),但这也不一定是最佳的。更好的解决方案是像 DataStax 的 Storage Attached Indexes,但它们还没有在 OSS Cassandra 中。另一个解决方案可能是集成真正的搜索引擎,例如 Solr(称为 DSE 搜索)或 Elasticsearch(如 Elassandra)。

要考虑的主要事情是分析延迟要求,在某些情况下,最好有一个单独的 table 标签作为分区键,但在这种情况下你可能有数据倾斜,因为没有那么多标签,数据分布不均匀。