CreateIndex

全局二级索引可以在创建表的时候创建,也可以在创建完表之后新增,全局二级索引里的字段需要在创建表的时候通过defined_columns预先指定。

预创建索引

schema_of_primary_key = [('gid', 'INTEGER'), ('uid', 'STRING')]
defined_columns = [('i', 'INTEGER'), ('bool', 'BOOLEAN'), ('d', 'DOUBLE'), ('s', 'STRING'), ('b', 'BINARY')]
table_meta = TableMeta(table_name, schema_of_primary_key, defined_columns)
table_option = TableOptions(-1, 1)
reserved_throughput = ReservedThroughput(CapacityUnit(0, 0))
secondary_indexes = [
    SecondaryIndexMeta('index1', ['i', 's'], ['gid', 'uid', 'bool', 'b', 'd']),
    ]
client.create_table(table_meta, table_option, reserved_throughput, secondary_indexes)
			

新增索引

index_meta = SecondaryIndexMeta('index2', ['i', 's'], ['gid', 'uid', 'bool', 'b', 'd'])
client.create_secondary_index(table_name, index_meta)

删除索引

client.delete_secondary_index(table_name, 'index1')