我需要从包含二级索引的表中获取记录。但是我得到“错误请求:不支持带有第二个索引的ORDER BY”。错误。我知道cassandra服务器中的CQL3不支持此功能。如何实现此功能?
以下是我的表结构和索引创建和选择查询。
1.在cassandra中创建表:
CREATE COLUMNFAMILY message_log(conversationid bigint,starttime timestamp,flag boolean,user_id text,expert_id text,conv_initiator_id text,message text,PRIMARY KEY(conversationid,starttime)) ;
2.创建索引: CREATE INDEX message_log_idx_conv_initiator_id ON message_log(conv_initiator_id);
CREATE INDEX message_log_idx_flag ON message_log (flag);
3.从表中获取记录: select messageid,user_id,expert_id,来自message_log的消息,其中conv_initiator_id ='manoj@1921.168.1.64'AND flag = true ORDER BY starttime ASC允许过滤。
I get "Bad Request: ORDER BY with 2ndary indexes is not supported.", when I run 3rd query.
我的模块的Erlang部分是:
get_chat_history_by_userid(从) - >
{ok, Pid} = seestar_session:start_link("localhost", 9042),
QryUse = "USE mykeyspace;",
case seestar_session:perform(Pid, QryUse, one) of
{ok,_Result} ->
FromJid = From#jid.luser++"@"++From#jid.lserver,
Flag = true,
QueryFinal=lists:concat(["select conversationid,user_id,expert_id,message from message_log
where conv_initiator_id = ","'",FromJid ,"'", " AND flag =",Flag," ORDER BY starttime ASC"," ALLOW FILTERING"]),
case seestar_session:perform(Pid,QueryFinal,one) of
{ok,_RecordList} ->
{rows,_ColumnNames,_Records} = _RecordList,
?INFO_MSG("selecting records from database using userid ~p",[_Records]),
_Records;
{error,_Error} ->
?INFO_MSG("Error occured while selecting records from database using userid~p",[_Error])
end;
{error,_Error} ->
?INFO_MSG(" Error occured while executing use query ~p",[_Error])
end.