Data-REST and dynamoDB and trying to sort my GSI object as follows, is it possible to sort GSI Hashkey in dynamoDB, Domain class
@DynamoDBTable(tableName = "test")
public class Test implements Serializable{
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String desc;
@DynamoDBHashKey(attributeName="id")
@DynamoDBAutoGeneratedKey
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@DynamoDBIndexHashKey(attributeName="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@DynamoDBAttribute(attributeName="desc")
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
public interface TestRepository extends PagingAndSortingRepository{
@EnableScan
@EnableScanCount
public Page<Test> findByName(@Param("name") String name, Pageable pageable);
public Page<Test> findByNameOrderByNameAsc(@Param("name") String name, Pageable pageable);
}
Is it possible to use orderBy on secondary Index because am using a hashkey of autogenerated so cant combine with hashkey attribute with Range key to fetch all possible results. I need to fetch names satisfying the search and orderBy name(GSI). Or else DynamoDB supports only orderBy through hashkey and range key as in Demo?
When I do this am getting an exception as "Cant use orderBy on scan query".
UPDATED: Am using Spring Data DynamoDB, I have created a GSI hash and key index in DynamoDB in the name "description-name-index" and I like to sort its data using range key by findBy of hash key. Here is my test code, Domain Class
@DynamoDBTable(tableName = "test")
public class Test implements Serializable{
private static final long serialVersionUID = 1L;
private String id;
private String description;
private String name;
@DynamoDBIndexHashKey(attributeName="description")
public String getDescription() {
return tesId;
}
public void setDescription(String description) {
this.setDescription(description);;
}
@DynamoDBIndexRangeKey(attributeName="name")
public String getName() {
return name;
}
public void setName(String name) {
this.setName(name);
}
@DynamoDBHashKey(attributeName="id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
and tries to fetch and sort data using findByDescriptionOrderByNameDesc(@Param("decription") String description, Pageable pageable)
and also I tried using @Id
and placed index hash and range key in a class but all in vain. Am getting 500 Internal Error
but not throwing any message too. Is there any way to use GSI hash and range pair and sort them.