If you want to delete only the hash key, you need to first query the records and then use batchDelete to delete all the records.
HashMap<String, AttributeValue> eav = new HashMap<String, AttributeValue>(); eav.put(":v1", new AttributeValue().withS(value)); DynamoDBQueryExpression<DocumentTable> queryExpression = new DynamoDBQueryExpression<DocumentTable>() .withKeyConditionExpression("documentId = :v1") .withExpressionAttributeValues(eav); List<DocumentTable> ddbResults = dynamoDBMapper.query(DocumentTable.class, queryExpression); dynamoDBMapper.batchDelete(ddbResults);
I would like to say here that deleteItem deletes only one element at a time, and for this you need to specify both a hash key and a range key.
source share