Create a new table + index:
public static void createIndex(String TABLE_NAME) throws IOException {
String familyName = "entry:";
byte[] FAMILY = Bytes.toBytes(familyName);
IndexedTableAdmin admin;
IndexedTable table;
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
desc.addFamily(new HColumnDescriptor(FAMILY));
String[] columns = { "hostname", "msg" };
for (int i = 0; i <>
byte[] COL_NAME = Bytes.toBytes(familyName + columns[i].toString());
String INDEX_COL_NAME = columns[i].toString();
IndexSpecification colIndex = new IndexSpecification(INDEX_COL_NAME, COL_NAME);
desc.addIndex(colIndex);
}
admin = new IndexedTableAdmin(getConfig());
// creates new table
admin.createTable(desc);
table = new IndexedTable(getConfig(), desc.getName());
}
So, once this is run, the following happens:
Table: TABLE_NAME is created with indexes on "entry:hostname" and "entry:msg"
Table: TABLE_NAME-hostname is created
Table: TABLE_NAME-msg is created
Great, so now there is one table and two index tables.
We can now push some data into it. Before doing this however, we need to make a configuration change to HBase.
In $HBASE_HOME/conf/hbase-site.xml add the following:
This will start the indexing service (if that's the right terminology). Restart HBase and push some data into the table. Once you've done this and you scan either of the index tables you'll see it working.