为索引python附加时间戳字符串

问题描述 投票:1回答:1

我正在使用Google App Engine,标准环境,NDB数据存储区,Python 2.7。每个项目最多只能有200个索引。

为了减少索引数量,我打算这样做:

我有三个字段,模型中的report_typecurrent_center_urlsafe_keytimestamp_entered。我需要在数据存储中查找所有条目具有current_center_urlsafe_key和report_type的特定值。我需要根据输入的时间戳(升序和降序)。

这将消耗

单独的复合索引

,而我想避免。为了实现此查询,我计划通过合并所有三个值来为每次写入添加一个单独的实体,如下所示:center_urlsafe_key_report_type_timestamp = report_type + "***" + current_center_urlsafe_key + str(current_timestamp_ms)
然后我打算进行如下查询:

current_timestamp_ms = int(round(time.time() * 1000)) current_date = date.today() date_six_months_back = common_increment_dateobj_by_months(self,current_date, -6) six_month_back_timestamp = (date_six_months_back - date(1970, 1, 1)).total_seconds() * 1000 center_urlsafe_key_report_type_timestamp = report_type_selected + "***" + current_center_urlsafe_key + str(six_month_back_timestamp) download_reports_forward = download_report_request_model.query(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp') >= center_urlsafe_key_report_type_timestamp).order(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp')) download_reports_backward = download_report_request_model.query(ndb.GenericProperty('center_urlsafe_key_report_type_timestamp') >= center_urlsafe_key_report_type_timestamp).order(ndb.GenericProperty('-center_urlsafe_key_report_type_timestamp'))

我的问题是,如果我将时间戳记添加为字符串,并添加前缀[[report_type +“ ****” + current_center_urlsafe_key
,NDB数据存储区不等式过滤器是否会提供所需的结果?
google-app-engine google-cloud-datastore
1个回答
2
投票
a-123-20191001 a-123-20190901 a-123-20190801 b-123-20191001 b-123-20190901 b-123-20190801

现在,如果您执行“ key> = a-123-20190801”,您将获得自2019/08/01起的所有前缀“ a-123”的数据,但最终所有的数据都将以“ b-”,因为“ b-*”> =“ a-123-20190801”。但是,如果您执行“键> = a-123-20190801和键<= a-123-20191001”,那么您的数据将仅属于该前缀。

© www.soinside.com 2019 - 2024. All rights reserved.