DynamoDB - 设置项目的全局二级索引 [英] DynamoDB - Global Secondary Index on set items

查看:26
本文介绍了DynamoDB - 设置项目的全局二级索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下属性的发电机表:

I have a dynamo table with the following attributes :

  • id(数字 - 主键)
  • 标题(字符串)
  • created_at(数字 - 长)
  • 标签(StringSet - 包含一组标签,比如 android、ios 等)

我希望能够通过标签进行查询 - 获取所有标记为 android 的项目.我怎样才能在 DynamoDB 中做到这一点?似乎全局二级索引只能基于 ScalarDataTypes(即数字和字符串)而不是集合内的项目.

I want to be able to query by tags - get me all the items tagged android. How can I do that in DynamoDB? It appears that global secondary index can be built only on ScalarDataTypes (which is Number and String) and not on items inside a set.

如果我采用的方法是错误的,另一种方法是创建不同的表或更改属性也可以.

If the approach I am taking is wrong, an alternative way for doing it either by creating different tables or changing the attributes is also fine.

推荐答案

  • DynamoDB 并非旨在优化设置值的索引.以下是亚马逊相关文档的副本(来自 Improving Data Access with Secondary Indexes在 DynamoDB 中).
  • 索引的键模式.索引键模式中的每个属性必须是字符串、数字或二进制类型的顶级属性.不允许嵌套属性和多值集.其他键模式的要求取决于索引的类型:对于全局二级索引,hash属性可以是任意标量表属性.范围属性是可选的,它也可以是任何标量表属性.对于本地二级索引,哈希属性必须与表的 hash 属性和 range 属性相同必须是非键表属性.

    The key schema for the index. Every attribute in the index key schema must be a top-level attribute of type String, Number, or Binary. Nested attributes and multi-valued sets are not allowed. Other requirements for the key schema depend on the type of index: For a global secondary index, the hash attribute can be any scalar table attribute. A range attribute is optional, and it too can be any scalar table attribute. For a local secondary index, the hash attribute must be the same as the table's hash attribute, and the range attribute must be a non-key table attribute.

    • 亚马逊建议为此类问题创建一个单独的一对多表.更多信息:使用一对多表
    • 这篇关于DynamoDB - 设置项目的全局二级索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆