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

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

问题描述

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

I have a dynamo table with the following attributes :


  • id(数字-主键)

  • 标题(字符串)

  • created_at(数字-长整数)

  • 标签(字符串集-包含一组标签,例如android,ios等。,)

  • id (Number - primary key )
  • title (String)
  • created_at (Number - long)
  • tags (StringSet - contains a set of tags say android, ios, etc.,)

我希望能够通过标签查询-让我将所有标记为android的项目 。如何在DynamoDB中做到这一点?看来全局二级索引只能建立在ScalarDataTypes(即Number和String)上,而不能建立在集合内的项目上。

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并非旨在优化设置值的索引。以下是亚马逊相关文档的副本(来自使用二级索引改善数据访问在DynamoDB中)。

    • DynamoDB is not designed to optimize indexing on set values. Below is a copy of the amazon's relevant documentation (from Improving Data Access with Secondary Indexes in DynamoDB).

    • 索引的关键架构。索引键架构
      中的每个属性必须是String,Number或Binary类型的顶级属性。
      不允许使用嵌套属性和多值集。关键模式的其他
      要求取决于索引的类型:对于
      全局二级索引,hash属性可以是任何标量表
      属性。 range属性是可选的,它也可以是任何标量
      表属性。对于本地二级索引,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.




      • Amazon建议针对此类问题创建单独的一对多表。此处的更多信息:使用一对多表

        • Amazon recommends creating a separate one-to-many table for these kind of problems. More info here : Use one to many tables
        • 这篇关于DynamoDB-设置项目的全局二级索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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