How to create Global Secondary Index for Json Attributes(column values) in Amazon Dynamo DB in C#?

好久不见. 提交于 2019-12-09 13:46:04

问题


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"}

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

..

回答1:


Taken from 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: If I have nested JSON data in DynamoDB, can I retrieve only a specific element of that data?

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.




回答2:


You can create a GSI or LSI on any top-level JSON element. So you have to bring the json element to column level and then create the index.



来源:https://stackoverflow.com/questions/34287356/how-to-create-global-secondary-index-for-json-attributescolumn-values-in-amazo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!