Question 1
For map collections Cassandra allows creation of an index on keys, values or entries (this is available only for maps).
So, first you would create your index on the map:
CREATE INDEX <index_name> ON <table_name> (ENTRIES(<map_column>));
Then you could query:
SELECT * FROM <table_name> WHERE <map_column>['<map_key>'] = '<map_value>';
Another solution would be to froze your collection and create an index on it:
CREATE INDEX <index_name> ON table (FULL(<map_column>));
Then you could query for values with:
SELECT * FROM <table_name> WHERE <map_column> = ['<value>'...];
I think the above solutions are not very good since you could easily scan your whole cluster. Your access type will use and index and not a partition key.
Question 2
Another solution would be to create a table like this:
CREATE TABLE <table_name> ( key TEXT, value TEXT, name TEXT, PRIMARY KEY ((key, value), name));
Key and value columns will hold the values for the tags. They will also be partition key so you could query your data like:
SELECT * FROM <table_name> WHERE key = 'key' AND value = 'value';
You will need to run several queries in order to search for all tags, but you can aggregate the result at the application level.
CREATE TABLE bwlists (
uuid uuid PRIMARY KEY,
bwl map<ascii, bw map<ascii, ascii>>);
Bad Request: line 1:79 no viable alternative at input '>'
Your first problem, is that you are trying to name the map within the bw map. That's not going to work, as CQL is not expecting to find an identifier (instead of a type). Your syntax can then be adjusted to this:bwl
CREATE TABLE bwlists (
uuid uuid PRIMARY KEY,
bwl map<ascii, map<ascii, ascii>>);
But that still doesn't work. Running this statement yields this message:CREATE
<ErrorMessage code=2000 [Syntax error in CQL query]
message="map type cannot contain another collection">
Currently, Cassandra/CQL does not permit creating a "map of a map."
Also, it's not a good idea to use reserved words as column names, even if Cassandra lets you do it. I'd rename to something more context-specific to your application.uuid