Additional secondary indexes in DynamoDB

I am moving my save level from Riak to DynamoDB. My data model contains an optional business identifier field that I would like to request as an alternative to the key.

It seems that DynamoDB secondary indexes cannot be null and require a range key, so despite the same name for Riak secondary indexes, make it a completely different beast.

Is there an elegant way to efficiently query my optional field without adding data in an external search index?

+6
source share
1 answer

When you asked this question, DynamoDB did not have global secondary indexes: http://aws.amazon.com/about-aws/whats-new/2013/12/12/announcing-amazon-dynamodb-global-secondary-indexes/

Now yes.

The local secondary index is best perceived and acts as a secondary range key. @andreimarinescu is right: you still have to request the hash key of the element, only with a secondary index can you use a limited subset of DynamoDB query comparison operators for this range key (e.g. more, less, etc.) So you still need to know in which "hash bucket" you are comparing inside.

Global secondary indices are a bit of another beast. They are more like a secondary version of your spreadsheet (and Amazon also charges you a similar bandwidth charge). You can use the non-primary key attributes of your table as primary key attributes of your index in the global secondary index and query them accordingly.

For example, if your table looks like this:

 |**Hash key**: Item ID | **Range Key**: Serial No | **Attribute**: Business ID | -------------------------------------------------------------------------------- | 1 | 12345 | 1A | -------------------------------------------------------------------------------- | 2 | 45678 | 2B | -------------------------------------------------------------------------------- | 3 | 34567 | (empty) | -------------------------------------------------------------------------------- | 3 | 12345 | 2B | -------------------------------------------------------------------------------- 

Then, with the local secondary index on the Business ID , you could perform queries such as "find all elements with a hash key of 3 and a business identifier of 2B " but you could not perform "find all elements with a business identifier equal to 2B "because the secondary index requires a hash key.

If you want to add a global secondary index using a business identifier, you can perform such queries. You essentially have to provide an alternate primary key for the table. You can run a query like "find all elements with a business identifier equal to 2B and get elements 2-45678 and 3-12345 as an answer.

Rare indexes work great with DynamoDB; it is entirely conceivable that not all elements have a business identifier and may allow you to provide the bandwidth provided by your index lower than the table, depending on the number of elements that you expect to have a business identifier.

+10
source

Source: https://habr.com/ru/post/953548/


All Articles