Compound Index (Multi-Field-Index)
Combining multiple fields to one identifier/index.
Since the access does not always necessarily take place on the unique identifier, there is also the possibility to combine several fields at the same time to an index. This annotation is used for this function:
@CompoundIndex(value = { @Index("fieldName1"), @Index(value = "fieldName2", ascending = false) }, uniqueIndex = true)
In the example, an index is created on the firstName
and lastName
of the Customer
entity, which would speed up the method findFirstByFirstNameAndLastName(String first, String last);
.
It's possible to add multiple @CompoundIndex
annotations in one entity.
Example of multiple fields combined to one index:
Last updated