Google app engine 为索引python追加时间戳字符串
我正在使用谷歌应用程序引擎、标准环境、NDB数据存储、Python 2.7。每个项目有200个索引的限制 为了减少索引数量,我计划这样做: 我有三个字段,报告类型,当前中心和在模型中输入的时间戳。我需要在数据存储中查找所有条目,这些条目具有当前\u center\u urlsafe\u键和报告\u类型的特定值。我需要根据输入的时间戳对这些值进行排序(升序和降序) 这将消耗一个独立的综合指数,我想避免它。为了实现此查询,我计划通过组合所有三个值为每次写入添加一个单独的实体,如下所示:Google app engine 为索引python追加时间戳字符串,google-app-engine,google-cloud-datastore,Google App Engine,Google Cloud Datastore,我正在使用谷歌应用程序引擎、标准环境、NDB数据存储、Python 2.7。每个项目有200个索引的限制 为了减少索引数量,我计划这样做: 我有三个字段,报告类型,当前中心=”和“=a-123-20190801”,您将获得2019/08/01年以来前缀“a-123”的所有数据,但您也将获得以“b-”开头的所有数据,因为“b-*”>=“a-123-20190801”。但是,如果您执行“key>=a-123-20190801”和“key Yes.Thank”-将同时包含“>=和Yes,只需确保示例中
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'))
然后我计划进行如下查询:
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\u type+“****”+current\u center\u urlsafe\u key,NDB数据存储不平等过滤器是否会提供所需的结果?该策略存在问题。您需要同时具有“>=”和“=a-123-20190801”,您将获得2019/08/01年以来前缀“a-123”的所有数据,但您也将获得以“b-”开头的所有数据,因为“b-*”>=“a-123-20190801”。但是,如果您执行“key>=a-123-20190801”和“key Yes.Thank”-将同时包含“>=和Yes,只需确保示例中的当前时间戳随着时间的推移而增加。如果使用unix时间(以秒/毫秒为单位)而没有任何格式设置,它的行为将与预期的一样。