Here is my cassandra table for chat kind of application:
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when, to_id)
);
This query work:
select * from tax_keyspace_dev.chat_messages where participants='[email protected][email protected]' order by when;
but following queries don't work:
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;
Error is "Bad Request: PRIMARY KEY part to_id cannot be restricted (preceding part when is either not restricted or by a non-EQ relation)"
update tax_keyspace_dev.chat_messages set read=true where participants = '[email protected][email protected]' and when = '2014-04-10 17:44:22+0530';
Error is "Bad Request: Missing mandatory PRIMARY KEY part to_id"
If I remove "to_id" from composite key and create separate index like this:
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when)
);
CREATE INDEX idx_chat_messages_to ON tax_keyspace_dev.chat_messages (to_id);
then other queries work but this one fails:
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;
with error "Bad Request: ORDER BY with 2ndary indexes is not supported."
How do I design my table so that all these use cases can work?
select * from tax_keyspace_dev.chat_messages where participants='[email protected][email protected]' order by when;
update tax_keyspace_dev.chat_messages set read=true where participants = '[email protected][email protected]' and when = '2014-04-10 17:44:22+0530';
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;