Cassandra的cqlsh操作

  1. 建库
CREATE KEYSPACE twitter WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1};
  1. 建表
CREATE TABLE IF NOT EXISTS twitter.hotels (
id UUID,
name varchar,
address varchar,
primary key(id)
);
  1. 查询
cqlsh> desc keyspaces;

twitter      system         system_distributed  system_schema
system_auth  elastic_admin  system_traces     

cqlsh> use twitter ;
cqlsh:twitter> desc tables;

"_doc"  hotels
cqlsh:twitter> desc table "_doc"; #查看表结构
cqlsh:twitter> select * from hotels ;
#name不是primary key必须加allow filtering
cqlsh:twitter> SELECT * FROM hotels WHERE name='7天' allow filtering;
#使用contains 对list、set集合中的元素进行过滤
cqlsh:twitter> select * from "_doc" where user contains 'Jimmy' allow filtering;
// 使用contains key 对map集合进行过滤
cqlsh:twitter> select * from users where scores contains key 'english' allow filtering;

count查询

select count(location) from surf_chn_mul_hor.surf_chn_mul_hor ;

数量过大查询无效

OperationTimedOut: errors={'127.0.0.1': 'Client request timeout. See Session.execute[_async](timeout)'}, last_host=127.0.0.1
  1. 更新
    where必须为primary key字段
  2. 删除表
drop table radar;

你可能感兴趣的:(Cassandra)