Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Spring Data Methods

Spring Data Aerospike supports defining queries by method name in the Repository interface and Spring will generate the necessary bodies. The format of the name is fairly flexible, consisting of a verb and a criteria.

Some of the verbs include find, query, read, get, count and delete. For example: countByLastName or findByFirstName.

Simple property repository queries

KeywordRepository query sampleSnippetNotes
Is, Equals or no keywordfindByLastName(String lastName)…where x.lastName = ?
Not, IsNotfindByLastNameNot(String lastName)…where x.lastName <> ?
True, isTruefindByEnabledTrue()…where x.enabled = true
False, isFalsefindByEnabledFalse()…where x.enabled = false
In, IsInfindByLastNameIn(Collection&lt;String&gt;)…where x.lastName in ?
NotIn, IsNotInfindByLastNameNotIn(Collection&lt;String&gt;)…where x.lastName not in ?
Null, IsNullfindByEmailAddressIsNull()…where x.emailAddress = null or x.emailAddress does not existThe same as “does not exist”. Objects and fields exist in Aerospike when their value is not equal to null.
Exists NotNull, IsNotNullfindByEmailAddressExists(), findByEmailAddressNotNull()…where x.emailAddress != null”Exists” and “IsNotNull” represent the same functionality and can be used interchangeably. Objects and fields exist in Aerospike when their value is not equal to null.
LessThan, IsLessThanfindByAgeLessThan(int age), findByFirstNameLessThan(String string)…where x.age < ?, where x.firstName < ?Strings are compared by order of each byte, assuming they have UTF-8 encoding. See information about ordering.
LessThanEqual, IsLessThanEqualfindByAgeLessThanEqual(int age), findByFirstNameLessThanEqual(String string)…where x.age <= ?, …where x.firstName <= ?Strings are compared by order of each byte, assuming they have UTF-8 encoding. See information about ordering.
GreaterThan, IsGreaterThanfindByAgeGreaterThan(int age), findByFirstNameGreaterThan(String string)…where x.age > ?, …where x.firstName > ?Strings are compared by order of each byte, assuming they have UTF-8 encoding. See information about ordering.
GreaterThanEqual, IsGreaterThanEqualfindByAgeGreaterThanEqual(int age), findByFirstNameGreaterThanEqual(String string)…where x.age >= ?, …where x.firstName >= ?Strings are compared by order of each byte, assuming they have UTF-8 encoding. See information about ordering.
Between, IsBetweenfindByAgeBetween(int lowerLimit, int upperLimit), findByFirstNameBetween(String lowerLimit, String upperLimit)…where x.age between ? and ?, …where x.firstName between ? and ?Strings are compared by order of each byte, assuming they have UTF-8 encoding. See information about ordering.
Before, IsBeforefindByDateOfBirthBefore(Date date)…where x.dateOfBirth < ?
After, IsAfterfindByDateOfBirthAfter(Date date)…where x.dateOfBirth > ?
Like, IsLike, MatchesRegexfindByLastNameLike(String lastNameRegex)…where x.lastName like ?
StartingWith, IsStartingWith, StartsWithfindByLastNameStartingWith(String string)…where x.lastName like ‘abc%‘
EndingWith, IsEndingWith, EndsWithfindByLastNameEndingWith(String string)…where x.lastName like ‘%abc’
Containing, IsContaining, ContainsfindByLastNameContaining(String substring)…where x.lastName like ‘%abc%
NotContaining, IsNotContaining, NotContainsfindByLastNameNotContaining(String substring)…where x.lastName not like ‘%abc%‘
AndfindByLastNameAndFirstName(String lastName, String firstName)…where x.lastName = ? and x.firstName = ?
OrfindByLastNameOrFirstName(String lastName, String firstName)…where x.lastName = ? or x.firstName = ?

Collection repository queries

KeywordRepository query sampleSnippetNotes
Is, Equals or no keywordfindByStringList(Collection<String> stringList)…where x.lastName = ?
Not, IsNotfindByStringListNot(Collection<String> stringList)…where x.lastName <> ?
InfindByStringListIn(Collection<Collection<String>>)…where x.lastName in ?Find records where stringList bin value equals one of the collections in the given argument.
Not InfindByStringListNotIn(Collection<Collection<String>>)…where x.lastName not in ?Find records where stringList bin value is not equal to any of the collections in the given argument.
Null, IsNullfindByStringListIsNull()…where x.emailAddress = null or x.emailAddress does not existThe same as “does not exist”. Objects and fields exist in Aerospike when their value is not equal to null.
Exists NotNull, IsNotNullfindByStringListExists(), findByStringListNotNull()…where x.emailAddress != null”Exists” and “IsNotNull” represent the same functionality and can be used interchangeably. Objects and fields exist in Aerospike when their value is not equal to null.
LessThan, IsLessThanfindByStringListLessThan(Collection<String> stringList)…where x.age < ?, where x.firstName < ?Find records where stringList bin value has fewer elements or has a corresponding element lower in ordering than in the given argument. See information about ordering.
LessThanEqual, IsLessThanEqualfindByStringListLessThanEqual(Collection<String> stringList)…where x.age <= ?, …where x.firstName <= ?Find records where stringList bin value has smaller or the same amount of elements or has each corresponding element lower in ordering or the same as in the given argument. See information about ordering.
GreaterThan, IsGreaterThanfindByStringListGreaterThan(Collection<String> stringList)…where x.age > ?, …where x.firstName > ?Find records where stringList bin value has more elements or has a corresponding element higher in ordering than in the given argument. See information about ordering.
GreaterThanEqual, IsGreaterThanEqualfindByStringListGreaterThanEqual(Collection<String> stringList)…where x.age >= ?, …where x.firstName >= ?Find records where stringList bin value has larger or the same amount of elements or has each corresponding element higher in ordering or the same as in the given argument. See information about ordering.
Between, IsBetweenfindByStringListBetween(Collection<String> lowerLimit, Collection<String> upperLimit)…where x.age between ? and ?, …where x.firstName between ? and ?Find records where stringList bin value is in the range between the given arguments. See information about ordering.
Containing, IsContaining, ContainsfindByStringListContaining(String string)…where x.lastName like ‘%abc%
NotContaining, IsNotContaining, NotContainsfindByStringListNotContaining(String string)…where x.lastName not like ‘%abc%‘
AndfindByStringListAndIntList(Collection<String> stringList, Collection<Integer> intList)…where x.lastName = ? and x.firstName = ?
OrfindByStringListOrIntList(Collection<String> stringList, Collection<Integer> intList)…where x.lastName = ? or x.firstName = ?

Map repository queries

KeywordRepository query sampleSnippetNotes
Is, Equals or no keywordfindByStringMap(Map<String, String> stringMap)…where x.lastName = ?
Not, IsNotfindByStringMapNot(Map<String, String> stringMap)…where x.lastName <> ?
InfindByStringMapIn(Collection<Map<String, String>>)…where x.lastName in ?Find records where stringMap bin value equals one of the maps in the given argument.
Not InfindByStringMapNotIn(Collection<Map<String, String>>)…where x.lastName not in ?Find records where stringMap bin value is not equal to any of the maps in the given argument.
Null, IsNullfindByStringMapIsNull()…where x.emailAddress = null or x.emailAddress does not existThe same as “does not exist”. Objects and fields exist in Aerospike when their value is not equal to null.
Exists NotNull, IsNotNullfindByStringMapExists(), findByStringMapNotNull()…where x.emailAddress != null”Exists” and “IsNotNull” represent the same functionality and can be used interchangeably. Objects and fields exist in Aerospike when their value is not equal to null.
LessThan, IsLessThanfindByStringMapLessThan(Map<String, String> stringMap)…where x.age < ?, where x.firstName < ?Find records where stringMap bin value has fewer elements or has a corresponding element lower in ordering than in the given argument. See information about ordering.
LessThanEqual, IsLessThanEqualfindByStringMapLessThanEqual(Map<String, String> stringMap)…where x.age <= ?, …where x.firstName <= ?Find records where stringMap bin value has smaller or the same amount of elements or has each corresponding element lower in ordering or the same as in the given argument. See information about ordering.
GreaterThan, IsGreaterThanfindByStringMapGreaterThan(Map<String, String> stringMap)…where x.age > ?, …where x.firstName > ?Find records where stringMap bin value has more elements or has a corresponding element higher in ordering than in the given argument. See information about ordering.
GreaterThanEqual, IsGreaterThanEqualfindByStringMapGreaterThanEqual(Map<String, String> stringMap)…where x.age >= ?, …where x.firstName >= ?Find records where stringMap bin value has larger or the same amount of elements or has each corresponding element higher in ordering or the same as in the given argument. See information about ordering.
Between, IsBetweenfindByStringMapBetween(Map<String, String> lowerLimit, Map<String, String> upperLimit)…where x.age between ? and ?, …where x.firstName between ? and ?Find records where stringMap bin value is in the range between the given arguments. See information about ordering.
Containing, IsContaining, ContainsfindByStringMapContaining(AerospikeQueryCriterion criterion, String string), findByStringMapContaining(AerospikeQueryCriterion criterionPair, String string, String value)…where x.lastName like ‘%abc%Find records where stringMap bin value (which is a Map) contains key “key1”: findByStringMapContaining(KEY, "key1"). Find records where stringMap bin value (which is a Map) contains value “value1”: findByStringMapContaining(VALUE, "value1"). Find records where stringMap bin value (which is a Map) contains key “key1” with the value “value1”: findByStringMapContaining(KEY_VALUE_PAIR, "key1", "value1")
NotContaining, IsNotContaining, NotContainsfindByStringNameNotContaining(AerospikeQueryCriterion criterion, String string)…where x.lastName not like ‘%abc%‘findByStringMapNotContaining(KEY, "key1"), findByStringMapNotContaining(VALUE, "value1"), findByStringMapNotContaining(KEY_VALUE_PAIR, "key1", "value1")
AndfindByStringMapAndIntMap(Map<String, String> stringMap, Map<Integer, Integer> intMap)…where x.lastName = ? and x.firstName = ?
OrfindByStringMapOrIntMap(Map<String, String> stringMap, Map<Integer, Integer> intList)…where x.lastName = ? or x.firstName = ?

POJO (Plain Old Java Object) repository queries

KeywordRepository query sampleSnippetNotes
Is, Equals or no keywordfindByAddress(Address address)…where x.lastName = ?
Not, IsNotfindByAddressNot(Address address)…where x.lastName <> ?
InfindByAddressIn(Collection<Address>)…where x.lastName in ?Find records where address bin value equals one of the Address objects in the given argument.
Not InfindByAddressNotIn(Collection<Address>)…where x.lastName not in ?Find records where address bin value is not equal to any of the Address objects in the given argument.
Null, IsNullfindByAddressIsNull()…where x.emailAddress = null or x.emailAddress does not existThe same as “does not exist”. Objects and fields exist in Aerospike when their value is not equal to null.
Exists NotNull, IsNotNullfindByAddressExists(), findByAddressNotNull()…where x.emailAddress != null”Exists” and “IsNotNull” represent the same functionality and can be used interchangeably. Objects and fields exist in Aerospike when their value is not equal to null.
LessThan, IsLessThanfindByAddressLessThan(Address address)…where x.age < ?, where x.firstName < ?Find records where address bin value (POJOs are stored in Aerospike as maps) has fewer elements or has a corresponding element lower in ordering than in the given argument. See information about ordering.
LessThanEqual, IsLessThanEqualfindByAddressLessThanEqual(Address address)…where x.age <= ?, …where x.firstName <= ?Find records where address bin value (POJOs are stored in Aerospike as maps) has smaller or the same amount of elements or has each corresponding element lower in ordering or the same as in the given argument. See information about ordering.
GreaterThan, IsGreaterThanfindByAddressGreaterThanEqual(Address address)…where x.age > ?, …where x.firstName > ?Find records where address bin value (POJOs are stored in Aerospike as maps) has more elements or has a corresponding element higher in ordering than in the given argument. See information about ordering.
GreaterThanEqual, IsGreaterThanEqualfindByStringMapGreaterThanEqual(Map<String, String> stringMap)…where x.age >= ?, …where x.firstName >= ?Find records where address bin value (POJOs are stored in Aerospike as maps) has larger or the same amount of elements or has each corresponding element higher in ordering or the same as in the given argument. See information about ordering.
Between, IsBetweenfindByAddressBetween(Address lowerLimit, Address upperLimit)…where x.age between ? and ?, …where x.firstName between ? and ?Find records where address bin value (POJOs are stored in Aerospike as maps) is in the range between the given arguments. See information about ordering.
AndfindByAddressAndFriend(Address address, Person friend)…where x.lastName = ? and x.firstName = ?
OrfindByAddressOrFriend(Address address, Person friend)…where x.lastName = ? or x.firstName = ?

Id repository queries

KeywordRepository query sampleSnippet
No keywordfindById(String id)…​where x.PK = ?
AndfindByIdAndFirstName(String id, String firstName)…where x.PK = ? and x.firstName = ?

Query modification

Query modifiers

KeywordRepository query sampleSnippet
IgnoreCasefindByLastNameIgnoreCase…where UPPER(x.lastName) = UPPER(?)
OrderByfindByLastNameOrderByFirstNameDesc…where x.lastName = ? order by x.firstName desc

Limiting query results

KeywordRepository query sampleSnippet
FirstfindFirstByAgeselect top 1 where x.age = ?
First NfindFirst3ByAgeselect top 3 where x.age = ?
TopfindTopByLastNameStartingWithselect top 1 where x.lastName like ‘abc%’ = ?
Top NfindTop4ByLastNameStartingWithselect top 4 where x.lastName like ‘abc%‘
DistinctfindDistinctByFirstNameContainingselect distinct …​ where x.firstName like ‘abc%’

Other useful special modifiers:

  • Distinct: Allows selection of unique results, for example findDistinctByLastName. Distinct is not supported by Spring Data Aerospike.
  • First or Top: Limit the number of results returned, for example findFirstByLastName or findTop20ByLastName.

An example of an interface with several query methods is:

public interface PersonRepository extends AerospikeRepository<Person, Long> {
public List<Person> findByLastName(String lastName);
public List<Person> findByLastNameContaining(String lastName);
public List<Person> findByLastNameStartingWith(String lastName);
public List<Person> findByLastNameAndFirstNameContaining(String lastName, String firstName);
public List<Person> findByAgeBetween(long startAge, long endAge);
public Optional<Person> findById(Long id);
}

Note that Java Dates are stored as type long in the database so search method should access them as if they are of type long. So if the class has a DateOfBirth field, instead of

public List<Person> findByDateOfBirthBetween(Date startDate, Date endDate);

there might be a method like:

public List<Person> findByDateOfBirthBetween(long startDate, long endDate);
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?