DynamoDB 在地图或列表类型上创建索引
DynamoDB create index on map or list type
我正在尝试向 DynamoDB 中地图对象内的属性添加索引,但似乎找不到这样做的方法。这是受支持的东西还是索引真的只允许标量值使用?围绕此的文档似乎很少。我希望索引功能类似于 MongoDB,但到目前为止,我采用的使用点语法将属性引用到索引的方法还没有成功。感谢您提供任何帮助或其他信息。
索引只能建立在顶级 JSON 属性上。此外,范围键必须是 DynamoDB 中的标量值(字符串、数字、二进制或布尔值之一)。
来自http://aws.amazon.com/dynamodb/faqs/:
Q: Is querying JSON data in DynamoDB any different?
No. You can create a Global Secondary Index or Local Secondary Index
on any top-level JSON element. For example, suppose you stored a JSON
document that contained the following information about a person:
First Name, Last Name, Zip Code, and a list of all of their friends.
First Name, Last Name and Zip code would be top-level JSON elements.
You could create an index to let you query based on First Name, Last
Name, or Zip Code. The list of friends is not a top-level element,
therefore you cannot index the list of friends. For more information
on Global Secondary Indexing and its query capabilities, see the
Secondary Indexes section in this FAQ.
Q: What data types can be indexed?
All scalar data types (Number, String, Binary, and Boolean) can be
used for the range key element of the local secondary index key. Set,
list, and map types cannot be indexed.
我尝试在单独存储对象时执行 hash(str(object))。这个散列给了我一个整数(数字),我可以在它上面使用二级索引。 Below is a sample in python,重要的是使用每次为值生成相同散列键的散列函数。所以我正在使用 sha1.
# Generate a small integer hash:
import hashlib
def hash_8_digits(source):
return int(hashlib.sha1(source.encode()).hexdigest(), 16) % (10 ** 8)
我们的想法是在保持实体完整的同时保持整个对象较小。即,不是将对象序列化和存储为字符串并更改对象的整个使用方式,而是将较小的哈希值与实际列表或映射一起存储。
我正在尝试向 DynamoDB 中地图对象内的属性添加索引,但似乎找不到这样做的方法。这是受支持的东西还是索引真的只允许标量值使用?围绕此的文档似乎很少。我希望索引功能类似于 MongoDB,但到目前为止,我采用的使用点语法将属性引用到索引的方法还没有成功。感谢您提供任何帮助或其他信息。
索引只能建立在顶级 JSON 属性上。此外,范围键必须是 DynamoDB 中的标量值(字符串、数字、二进制或布尔值之一)。
来自http://aws.amazon.com/dynamodb/faqs/:
Q: Is querying JSON data in DynamoDB any different?
No. You can create a Global Secondary Index or Local Secondary Index on any top-level JSON element. For example, suppose you stored a JSON document that contained the following information about a person: First Name, Last Name, Zip Code, and a list of all of their friends. First Name, Last Name and Zip code would be top-level JSON elements. You could create an index to let you query based on First Name, Last Name, or Zip Code. The list of friends is not a top-level element, therefore you cannot index the list of friends. For more information on Global Secondary Indexing and its query capabilities, see the Secondary Indexes section in this FAQ.
Q: What data types can be indexed?
All scalar data types (Number, String, Binary, and Boolean) can be used for the range key element of the local secondary index key. Set, list, and map types cannot be indexed.
我尝试在单独存储对象时执行 hash(str(object))。这个散列给了我一个整数(数字),我可以在它上面使用二级索引。 Below is a sample in python,重要的是使用每次为值生成相同散列键的散列函数。所以我正在使用 sha1.
# Generate a small integer hash:
import hashlib
def hash_8_digits(source):
return int(hashlib.sha1(source.encode()).hexdigest(), 16) % (10 ** 8)
我们的想法是在保持实体完整的同时保持整个对象较小。即,不是将对象序列化和存储为字符串并更改对象的整个使用方式,而是将较小的哈希值与实际列表或映射一起存储。