DynamoDB query for attlibute set



我是 DynamoDB 的新手,目前正在尝试使用 Node.js 的 AWS 示例。我对本教程有一个问题:加载电影数据库和查询数据的 AWS 教程。

我想搜索指定演员出演的电影。 例如,"丹尼尔·布鲁尔"和"奥利维亚·王尔德"。 另一个例子,"丹尼尔·布鲁尔"或"休·杰克曼"。 另外,如果可能的话,我想搜索模糊(例如"???布鲁尔》)。

是否需要拆分表或定义过滤器?

示例数据:

{
"year" : 2013,
"title" : "Turn It Down, Or Else!",
"info" : {
"directors" : [
"Alice Smith",
"Bob Jones"
],
"release_date" : "2013-01-18T00:00:00Z",
"rating" : 6.2,
"genres" : [
"Comedy",
"Drama"
],
"image_url" : "http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg",
"plot" : "A rock band plays their music at high volumes, annoying the neighbors.",
"rank" : 11,
"running_time_secs" : 5215,
"actors" : [
"David Matthewman",
"Ann Thomas",
"Jonathan G. Neff"
]
}
}

架构:

TableName : "Movies",
KeySchema: [       
{ AttributeName: "year", KeyType: "HASH"},  //Partition key
{ AttributeName: "title", KeyType: "RANGE" }  //Sort key
],
AttributeDefinitions: [       
{ AttributeName: "year", AttributeType: "N" },
{ AttributeName: "title", AttributeType: "S" }
],
ProvisionedThroughput: {       
ReadCapacityUnits: 10, 
WriteCapacityUnits: 10
}

表格已填满:

allMovies.forEach(function(movie) {
var params = {
TableName: "Movies",
Item: {
"year":  movie.year,
"title": movie.title,
"info":  movie.info
}
};
docClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add movie", movie.title, ". Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("PutItem succeeded:", movie.title);
}
});

查看指定项目属性文档。您的info字段是 JSON,因此可以告诉 Dynamo 查看子字段、子子字段等。

然后,需要将这些与条件表达式结合使用以获得所需的功能。

请记住,尽管这些事情是可能的,但它们是否有效仍然取决于表架构。环顾四周,我认为您无法对actors子字段进行索引,因此如果您希望此类查询快速,则需要将该数据提取到其自己的列中以便在其上构建索引。

最新更新