简体   繁体   English

TransientError:临时搜索服务错误-Python Google App Engine搜索

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

I'm trying to run a query and sorting by 'updated_at' field using a large number_found_accuracy: 我正在尝试使用较大的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()

When get_result() is called i get the error bellow: 当调用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_ 文件“ /base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,行1535,在调用 rv = self.handle_exception(请求,响应,e ) 呼叫 rv = self.router.dispatch(request,响应)文件“ /base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,行1278,位于default_dispatcher返回route.handler_adapter(请求,响应)文件“ /base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py”,行1102,在调用返回处理程序中。dispatch()文件“ / base / data / home / apps / p〜imobzi-app / 20181127t101400.414282042583891084 / modules / base_handler.py“,第72行,在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 runtimes / python27g / 3b44e98ed7fbb86b / python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py“,第572行,在调度返回中self.handle_exception(e,self.app.debug)文件” / base / alloc / tmpfs / dynamic_runtimes / python27g / 3b44e98ed7fbb86b / python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py“,第570行,在分派返回方法中(* args,** kwargs)文件” / base / data / home /apps/p~imobzi-app/20181127t101400.414282042583891084/main.py“,第132行,在获取联系人= query_future.get_result()文件” / base / alloc / tmpfs / dynamic_runtimes / python27g / 3b44e98ed7fbb86b / python27 / python27_lib / versions /1/google/appengine/api/search/search.py​​“,第281行,在get_result中引发_ToSearchError(e)TransientError:临时搜索服务错误

The error occurs when i use "number_found_accuracy" and "sort_options" in same query when query result is large (this query return more than 50,000 results). 当查询结果较大(此查询返回超过50,000个结果)时,在同一查询中使用“ number_found_accuracy”和“ sort_options”时,将发生错误。

If "number_found_accuracy" or "sort_options" is removed from query_options i get the result normally, but if both is in query_options, the error occurs. 如果从query_options中删除了“ number_found_accuracy”或“ sort_options”,我可以正常得到结果,但是如果两者都在query_options中,则会发生错误。

In a normal case i'd remove "number_found_accuracy" from query, but i need to show the result count for the user and sort it by updated_at field. 在正常情况下,我将从查询中删除“ number_found_accuracy”,但我需要显示用户的结果计数,并按updated_at字段对其进行排序。 Does anyone know a way to solve this? 有谁知道解决这个问题的方法? This occurs only when a deploy project to server, in a local/development environment, everything works as expected. 仅当在本地/开发环境中将项目部署到服务器时,一切都会按预期工作时,才会发生这种情况。

One reason for this error can be that the length of the query exceeds the limit of 2000 characters as specified in the documentation . 发生此错误的原因之一可能是查询的长度超过了文档中指定的2000个字符的限制。

There is also a limitation on sorting that can be worked around by presorting your documents in the index using Document rank as explained in this StackOverflow answer . 通过使用Document rank对索引中的文档进行预排序,可以解决排序问题,如StackOverflow答案中所述

Also note that as per the documentation 另请注意,根据文档

number_found: number_found:
Returns an approximate number of documents matching the query. 返回与查询匹配的文档的大概数量。 QueryOptions defining post-processing of the search results. QueryOptions定义搜索结果的后处理。 If the QueryOptions.number_found_accuracy parameter were set to 100, then number_found <= 100 is accurate. 如果QueryOptions.number_found_accuracy参数设置为100,则number_found <= 100是正确的。

Since you have set number_found_accuracy=25000 , any search result with a size greater than 25000 will be an approximate. 由于已设置number_found_accuracy=25000 ,因此任何大小大于25000的搜索结果都是近似的。

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

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