TransientError: Temporary search service error - Python Google App Engine Search

TransientError: Temporary search service error - Python Google App Engine Search

我正在尝试 运行 查询并使用大 number_found_accuracy 按 'updated_at' 字段排序:

order_options = search.SortOptions(
    expressions=[search.SortExpression(expression='updated_at',
                                   direction=search.SortExpression.DESCENDING)])

query_options = search.QueryOptions(
    limit=50,
    cursor=search.Cursor(),
    sort_options=order_options,
    number_found_accuracy=25000)

index = search.Index('contacts', namespace='default')
query_future = index.search_async(search.Query("", options=query_options))
contacts = query_future.get_result()

当调用 get_result() 时,出现以下错误:

File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in call rv = self.handle_exception(request, response, e) File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in call rv = self.router.dispatch(request, response) File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response) File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in call return handler.dispatch() File "/base/data/home/apps/p~imobzi-app/20181127t101400.414282042583891084/modules/base_handler.py", line 72, in dispatch super(BaseHandler, self).dispatch() File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug) File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/p~imobzi-app/20181127t101400.414282042583891084/main.py", line 132, in get contacts = query_future.get_result() File "/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/1/google/appengine/api/search/search.py", line 281, in get_result raise _ToSearchError(e) TransientError: Temporary search service error

当我在同一查询中使用 "number_found_accuracy" 和 "sort_options" 时出现错误,当查询结果很大时(此查询 return 超过 50,000 个结果)。

如果从 query_options 中删除 "number_found_accuracy" 或 "sort_options" 我会正常得到结果,但如果两者都在 query_options 中,则会发生错误。

在正常情况下,我会从查询中删除 "number_found_accuracy",但我需要为用户显示结果计数并按 updated_at 字段对其进行排序。有谁知道解决这个问题的方法?只有在 local/development 环境中将项目部署到服务器时,才会发生这种情况,一切都按预期进行。

此错误的一个原因可能是查询的长度超过了 documentation 中指定的 2000 个字符的限制。

排序也有限制,可以通过使用文档排名在索引中对文档进行预排序来解决,如 this Whosebug answer 中所述。

另请注意,根据 documentation

number_found:
Returns an approximate number of documents matching the query. QueryOptions defining post-processing of the search results. If the QueryOptions.number_found_accuracy parameter were set to 100, then number_found <= 100 is accurate.

由于您设置了number_found_accuracy=25000,任何大于25000的搜索结果都是一个近似值。