@Retention(value=RUNTIME) @Target(value={FIELD,TYPE_USE}) @Documented public @interface Index
@Table(table = "my_entity")
public class MyEntity {
//Simple index
@Column
@Index
private String countryCode;
//Simple index with custom name
@Column("custom_name")
@Index(name = "country_code_idx")
private String customName;
//Index on collection
@Column
@Index
private List<String> indexedList;
//Full index on collection because of the usage of @Frozen
@Column
@Frozen
@Index
private List<String> indexedFullList;
//Index on map key
@Column("indexed_map_key")
private Map<@Index String, Long> indexOnMapKey;
//Index on map entry
@Column("index_map_entry")
@Index
private Map<String, Long> indexOnMapEntry;
//Custom index
@Column
@Index(indexClassName = "com.myproject.SecondaryIndex", indexOptions = "{'key1': 'value1', 'key2': 'value2'}")
private String custom;
...
}
The above code would produce the following CQL script for index creation:
CREATE INDEX IF NOT EXISTS ON my_entity(countryCode);
CREATE INDEX country_code_idx IF NOT EXISTS ON my_entity(custom_name);
CREATE INDEX IF NOT EXISTS ON my_entity(indexedlist);
CREATE INDEX IF NOT EXISTS ON my_entity(FULL(indexedfulllist));
CREATE INDEX IF NOT EXISTS ON my_entity(KEYS(indexed_map_key));
CREATE INDEX IF NOT EXISTS ON my_entity(ENTRY(index_map_entry));
CREATE CUSTOM my_entity_custom_index INDEX IF NOT EXISTS
ON my_entity(custom)
USING com.myproject.SecondaryIndex
WITH OPTIONS = {'key1': 'value1', 'key2': 'value2'};
/| Modifier and Type | Optional Element and Description |
|---|---|
String |
indexClassName
Optional.
|
String |
indexOptions
Optional.
|
String |
name
Optional.
|
public abstract String name
@Table
public class User {
...
@Index(name = "country_code_index")
@Column
private String countryCode;
...
}
If the index name was not set above, it would default to public abstract String indexClassName
public abstract String indexOptions
Copyright © 2012-2021. All Rights Reserved.