'Create "Composite Global Secondary Index" in dynamoDB
I need to create a composite GSI based on 3 different fields and query the data. I cannot find any resource which can point me to the correct direction and usage of this. Would appreciate some help on how this can be achieved ?
The table is as below:
@Data
@NoArgsConstructor
@DynamoDBTable(tableName = TABLE_NAME)
public class MyTable {
@DynamoDBHashKey(attributeName = NAME)
private String name;
private Person person;
}
Person.java
public class Person {
private String name;
private String age;
private Gender gender; //Gender is an enum : MALE, FEMALE, OTHER
private String occupation;
.
.
.
and so on
}
Do I need to create another object like PersonV2 and then create an index on it or it should be done in a different way ?
APPROACH :
public class PersonV2 {
private String name;
private String age;
private Gender gender;
}
and the my table will look like this ?
@Data
@NoArgsConstructor
@DynamoDBTable(tableName = TABLE_NAME)
public class MyTable {
@DynamoDBHashKey(attributeName = NAME)
private String name;
private Person person;
@DynamoDBIndexHashKey(attributeName = MY_INDEX_ATTRIBUTE_NAME, globalSecondaryIndexName = MY_INDEX_NAME)
private PersonV2 personV2;
}
Is this the correct way to handle this ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
