如何使用多个字段的哈希值创建DynamoDB全局二级索引?

问题描述

在我看来,“散列”一词表示,有可能对DynamoDB中由多个字段组成的散列。但是,我发现的每篇文章都显示仅由单个值组成的“哈希”……这对我来说没有任何意义。

我的表包含以下字段:

  • uid(PK)
  • 提供者
  • 标识符
  • 来自
  • 已收到日期
  • date_processed

目标是根据我的应用检索数据的方式来拥有多个索引(当然不是通过PK)。组合是:

  1. 通过提供者的消息标识符:
    所需的哈希:提供者+标识符

  2. 通过对话消息标识符:
    所需的哈希值:从+到

  3. 到收到日期为止,是否得到处理
    所需的哈希:_ac

  4. 到收到日期为止,是否得到处理
    所需的哈希:帐户

这是我尝试过但未成功的示例之一 ...

  MessagesTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: messages
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: uid
          AttributeType: S
        - AttributeName: account
          AttributeType: S
        - AttributeName: provider
          AttributeType: S
        - AttributeName: identifier
          AttributeType: S
        - AttributeName: from
          AttributeType: N
        - AttributeName: to
          AttributeType: N
        - AttributeName: _ac
          AttributeType: N
        - AttributeName: _ap
          AttributeType: N
      KeySchema:
        - AttributeName: uid
          KeyType: HASH
      GlobalSecondaryIndexes:
        - IndexName: idxConversation
          KeySchema:
            - AttributeName: from:to
              KeyType: HASH
            - AttributeName: _ac
              KeyType: RANGE
          Projection:
            ProjectionType: KEYS_ONLY
        - IndexName: idxProviderMessage
            KeySchema:
              - AttributeName: provider:identifier
                KeyType: HASH
              - AttributeName: _ac
                KeyType: RANGE
            Projection:
              ProjectionType: KEYS_ONLY

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)