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

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

问题描述

在DynamoDB中,我有一个表,其中每个记录都有两个日期属性, create_date last_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 i.e. 2016-01-22T16:19:52.464Z.

我需要可以根据 create_date last_modified_date 来查询它们,即

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


  • 获取所有记录,其中 create_date> [some_date]

  • 获取所有记录,其中 last_modified_date< [some_date]

  • 通常获取所有记录,其中 [date_attr] [comparison_op] [some_date] 等...

  • get all records where create_date > [some_date]
  • get all records where last_modified_date < [some_date]
  • in general get all records where [date_attr] [comparison_op] [some_date] etc...

一种方法是在每条记录中插入一个虚拟固定属性,并创建一个虚拟属性索引为分区键和 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 <, >, <=, >=, so on.

但这似乎并不好,看起来像是黑客,而不是适当的解决方案/设计。有没有更好的解决方案?

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

推荐答案

NoSQL DB有些不好的地方,但是您可以通过遵循以下解决方案来解决:

There are some things NoSQL DB are not good about, but you can solve this by following solutions:

解决方案1):将此表数据移到SQL数据库中以进行搜索:这是有效的,因为您将能够按照您的要求,有时这可能很乏味,因为您需要将数据之间同步到不同的数据库

Solution 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 to different DB's

解决方案2)与Amazon CloudSearch :您可以将此表与Cloudsearch集成,然后而不是查询DynamoDB表,您可以查询Cloudsearch

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

解决方案3) Elasticsearch :ElasticSearch与云类似,尽管它们各有利弊,但最终结果是相同的,而不是查询DynamoDB来查询Elasticsearch

Solution 3) Integrate with Elasticsearch: ElasticSearch is similar to cloud although each has some pros and cons, the end result would be same rather than querying DynamoDB query the Elasticsearch

4)正如您在问题中提到的那样,添加索引

Solution 4) As you have mentioned in your question add the indexes

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

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