from riak import RiakClient

client = RiakClient(protocol='pbc', host='127.0.0.1', http_port=8098)
xml_file = open('tweetsSchema.xml', 'r')
schema_data = xml_file.read()
print(schema_data)
client.create_search_schema('tweetsSchema', schema_data)
xml_file.close()
client.create_search_index("default", "tweetsSchema")
print(client.list_search_indexes())
create = """
CREATE TABLE {table} (
	family		varchar   not null,
	series      varchar   not null,
	time        timestamp not null,
	metric      double,
	PRIMARY KEY (
		(family, series, quantum(time, 1, 'd')
	),family, series, time))
"""

rc = RiakClient(host='localhost', pb_port=8087)

create_q = create.format(table=table_name)
print create_q

secs = datetime.timedelta(0, 5)
start = datetime.datetime.now() - datetime.timedelta(0,3600)

try:
	rc.ts_query("","DESCRIBE %s" % table_name)
except RiakError:
	rc.ts_query(table_name, create_q)

try:
  rc.get_search_index(node_table_name)
except RiakError:
  rc.create_search_index(node_table_name)

bucket = rc.bucket(node_table_name)
bucket.set_properties({'search_index':node_table_name})