Cassandra query on Map - Contains Clause [duplicate]

寵の児 提交于 2019-12-08 13:21:30

For this to work, you have to create a secondary index on the map. But, you first have to ask yourself if you want to index your map keys or values (cannot do both). Given your CQL statement, I'll assume that you want to index your map key (and we'll go from there).

CREATE INDEX table1_fetchMapKey ON table1(KEYS(fetchDataMap));

After inserting some data (making a guess as to what your Config UDT looks like), I can SELECT with a slightly modified version of your CQL query above:

aploetz@cqlsh:stackoverflow> SELECT * FROm table1 WHERE
    fetchDataMap CONTAINS KEY '233322554843924';

 userid | fetchdatamap
--------+------------------------------------------------------------
 B26354 | {'233322554843924': {key: 'location', value: '~/scripts'}}

(1 rows)

Note that I cannot in good conscience provide you with this solution, without passing along a link to the DataStax doc When To Use An Index. Secondary indexes are known to not perform well. So I can only imagine that a secondary index on a collection would perform worse, but I suppose that really depends on the relative cardinality. If it were me, I would re-model my table to avoid using a secondary index, if at all possible.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!