如何在 C# 中的 Amazon Dynamo DB 中为 Json 属性(列值)创建全局二级索引? [英] How to create Global Secondary Index for Json Attributes(column values) in Amazon Dynamo DB in C#?

查看:22
本文介绍了如何在 C# 中的 Amazon Dynamo DB 中为 Json 属性(列值)创建全局二级索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 Id 列和 JSON 列的表.

I have a table with column Id and JSON column.

Id       |       JSON
----------------------------------------------------------------
101      |  {"person_id":456,"f_name":"t", "l_name":"Jack"}
         |
102      |  {"person_id":123,"f_name":"M", "l_name":"Ron"}
         |
103      |  {"person_id":789,"f_name":"A", "l_name":"Tom"}

我能够在 Id 列上创建 GSI(全局二级索引),但我想知道如何在 person_idf_name 上创建 GSI.是否可以为 json 属性创建 GSI?根据观察,我能够在 Dynamo DB 表中的列上创建 GSI.请提供 C#.Net 示例..

I am able to create GSI(Global Secondary Index) on column Id , but I would like to know how to create GSI on person_id and f_name. Is it possible to create GSI for json attributes? As upon observation, I was able to create GSI on columns in tables of Dynamo DB..Please provide a C#.Net example..

推荐答案

取自 http://aws.amazon.com/dynamodb/faqs/

问:在 DynamoDB 中查询 JSON 数据有什么不同吗?

Q: Is querying JSON data in DynamoDB any different?

没有.您可以创建全局二级索引或本地二级索引在任何顶级 JSON 元素上.例如,假设您存储了一个 JSON包含有关某人的以下信息的文件:名字、姓氏、邮政编码和他们所有朋友的列表.名字、姓氏和邮政编码将是顶级 JSON 元素.您可以创建一个索引,让您根据名字、姓氏进行查询姓名或邮政编码.好友列表不是顶级元素,因此,您无法索引朋友列表.想要查询更多的信息有关全局二级索引及其查询功能,请参阅此常见问题解答中的二级索引部分.

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.

问:如果我在 DynamoDB 中嵌套了 JSON 数据,我可以只检索一个该数据的特定元素?

Q: If I have nested JSON data in DynamoDB, can I retrieve only a specific element of that data?

是的.使用 GetItem、BatchGetItem、Query 或 Scan API 时,您可以定义一个 ProjectionExpression 来确定哪些属性应该从表中检索.这些属性可以包括标量,JSON 文档的集合或元素.

Yes. When using the GetItem, BatchGetItem, Query, or Scan APIs, you can define a ProjectionExpression to determine which attributes should be retrieved from the table. Those attributes can include scalars, sets, or elements of a JSON document.

虽然我还没有设法做到这一点,或者看到任何关于云形成的例子.

Although I haven't managed to do it, or seen any examples of it being done with cloud formation.

这篇关于如何在 C# 中的 Amazon Dynamo DB 中为 Json 属性(列值)创建全局二级索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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