There is a DynamoDB table called 'Field', which has 'pageId' and 'config' fields. The 'config' field contains a list of JSON objects.
Field entity
@Data
@DynamoDBTable(tableName = "field")
public class Field{
@DynamoDBHashKey(attributeName = "pageId")
private String pageId;
@DynamoDBAttribute(attributeName = "config")
private List<Config> config;
}
Config entity
@Data
@DynamoDBDocument
public class Config{
@DynamoDBAttribute(attributeName = "fieldName")
private String fieldName;
@DynamoDBAttribute(attributeName = "fieldType")
private String fieldType;
}
The JSON representation of the data in DynamoDB.
{
"pageId": {
"S": "page_1"
},
"config": {
"L": [
{
"M": {
"fieldName": {
"S": "field_name_1"
},
"fieldType": {
"S": "type_2"
}
}
},
{
"M": {
"fieldName": {
"S": "field_name-2"
},
"fieldType": {
"S": "type_1"
}
}
}
]
}
}
How can I write code to directly filter the records in the 'field' table based on the 'fieldName' property of the 'config' field without fetching all the records and filtering them afterwards?
- javaVersion = 8
- springVersion = '5.1.18.RELEASE'
- springBootVersion = '2.1.6.RELEASE'
- AwsDynamoDBSdk = com.amazonaws:aws-java-sdk-dynamodb:1.11.548
You cannot. This is a limitation of DynamoDB. A common recipe is to combine this with Opensearch which you would populate using DynamoDB streams and a lambda. Here's a blog post on this.
DynamoDB has a limited ability to search data using queries - you can for example use
begins_withto filter on the sort key but that's about it.