基于时间戳的 DynamoDB 查询/排序 [英] DynamoDB query/sort based on timestamp

查看:27
本文介绍了基于时间戳的 DynamoDB 查询/排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 DynamoDB 中,我有一个表,其中每条记录都有两个日期属性,create_datelast_modified_date.这些日期采用 ISO-8601 格式,例如2016-01-22T16:19:52.464Z.

In DynamoDB, I have a table where each record has two date attributes, create_date and last_modified_date. These dates are in ISO-8601 format e.g. 2016-01-22T16:19:52.464Z.

我需要有一种基于 create_datelast_modified_date 查询它们的方法,例如

I need to have a way of querying them based on the create_date and last_modified_date e.g.

  • 获取 create_date > 的所有记录[some_date]
  • 获取 last_modified_date <的所有记录[some_date]

一般来说,我需要获取 [date_attr] [comparison_op] [some_date] 的所有记录.

In general, I need to get all records where [date_attr] [comparison_op] [some_date].

一种方法是在每条记录中插入一个虚拟固定属性,并创建一个索引,其中虚拟属性作为分区键,create_date 作为排序键(对于 last_modified_date.)

One way of doing it is to insert a dummy fixed attribute with each record and create an index with the dummy attribute as the partition key and the create_date as the sort key (likewise for last_modified_date.)

然后我可以通过提供固定的虚拟属性作为分区键、日期属性作为排序键并使用任何比较运算符<> 来查询它;<=>= 等.

Then I'll be able to query it as such by providing the fixed dummy attribute as partition key, the date attributes as the sort key and use any comparison operators <, >, <=, >=, and so on.

但这似乎不太好,看起来像是一种 hack,而不是正确的解决方案/设计.有没有更好的解决方案?

But this doesn't seem good and looks like a hack instead of a proper solution/design. Are there any better solutions?

推荐答案

NoSQL DB 有一些不擅长的地方,但是你可以通过以下解决方案来解决:

There are some things that NoSQL DBs are not good at, but you can solve this with the following solutions:

  1. 将此表数据移动到SQL数据库中进行搜索:这很有效,因为您可以根据需要进行查询,有时这可能很繁琐,因为您需要在两个不同的数据库之间同步数据

  1. Move this table data to SQL database for searching purpose: This can be effective because you will be able to query as per your requirement, this might be tedious sometimes because you need to synchronize the data between two different DBs

与亚马逊集成CloudSearch:您可以将此表与 CloudSearch 集成,然后您可以查询 Cloudsearch,而不是查询您的 DynamoDB 表

Integrate with Amazon CloudSearch: You can integrate this table with CloudSearch and then rather than querying your DynamoDB table you can query Cloudsearch

Elasticsearch:Elasticsearch 与 CloudSearch 类似,虽然各有优缺点,但最终结果是一样的——不是查询 DynamoDB,而是查询 Elasticsearch

Integrate with Elasticsearch: Elasticsearch is similar to CloudSearch although each has pros and cons, the end result would be same - rather than querying DynamoDB, instead query Elasticsearch

正如您在问题中提到的,添加 GSI 索引

As you have mentioned in your question, add GSI indexes

这篇关于基于时间戳的 DynamoDB 查询/排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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