简体   繁体   English

使用Google App Engine搜索的TransientError

[英]TransientError with Google App Engine Search

I'm trying to run a query and sorting by a date field. 我正在尝试运行查询并按日期字段排序。

q = self.request.get("q")
index = search.Index(name="transaction")

sort_options = search.SortOptions(
    expressions=[
        search.SortExpression(expression='timestamp_date', direction=search.SortExpression.DESCENDING)
    ],
    limit=1000)
options = search.QueryOptions(limit=30, cursor=search.Cursor(), sort_options=sort_options)

results = index.search(search.Query(query_string=q, options=options))

On the development server, the code works but the results are not correctly sorted . 在开发服务器上,代码可以正常工作,但结果未正确排序 On the production server it doesn't work at all; 在生产服务器上它根本不起作用; It gives the following error: 它给出以下错误:

Search failed
Traceback (most recent call last):
  File "/base/data/home/apps/s~xxx/pre-24.359846149527858049/main.py", line 78, in get
    results = index.search(search.Query(query_string=q, options=options))
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2609, in search
    _CheckStatus(response.status())
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 414, in _CheckStatus
    raise _ERROR_MAP[status.code()](status.error_detail())
TransientError

I'm wondering how to make it work on the production server and how to sort correctly on the development server. 我想知道如何使它在生产服务器上工作以及如何在开发服务器上正确排序。 I know its experimental technology, but I wanted to check to see if this was something I was overlooking 我知道它的实验技术,但我想查看这是否是我忽略的东西

You need to provide a default value for all SortExpressions. 您需要为所有SortExpressions提供默认值。 This will be made clear in a forthcoming release. 这将在即将发布的版本中明确说明。 Also there is no explicit support for default Date values yet, so you need to put a default numeric value representing the number of days since 1970-01-01. 此外,还没有明确支持默认日期值,因此您需要设置一个默认数值,表示自1970-01-01以来的天数。 In the code below, I am using the date 1970-01-01 as the default by specifying a value of 0. 在下面的代码中,我使用日期1970-01-01作为默认值,通过指定值0。

sort_options = search.SortOptions(
    expressions=[
        search.SortExpression(expression='timestamp_date', default_value=0)
    ])

Also note that you do not need to specify direction=search.SortExpression.DESCENDING as that is the default for direction. 另请注意,您不需要指定direction = search.SortExpression.DESCENDING,因为这是direction的默认值。 You do not need to specify the default value of 1000 for the limit either. 您也不需要为限制指定默认值1000。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM