个股论坛重做
This commit is contained in:
@@ -1301,7 +1301,23 @@ def es_search_proxy(index):
|
||||
try:
|
||||
body = request.get_json()
|
||||
print(f"[Community API] ES 搜索请求: index={index}, body={body}")
|
||||
result = es_client.search(index=index, body=body)
|
||||
|
||||
# 尝试使用不同的 API 调用方式(兼容不同版本的 elasticsearch-py)
|
||||
try:
|
||||
# 新版本 API
|
||||
result = es_client.search(index=index, body=body)
|
||||
except TypeError:
|
||||
# 旧版本 API,参数可能不同
|
||||
result = es_client.search(index=index, **body)
|
||||
|
||||
# 处理结果格式
|
||||
if hasattr(result, 'body'):
|
||||
result = result.body
|
||||
elif hasattr(result, '__getitem__'):
|
||||
pass # 已经是 dict
|
||||
else:
|
||||
result = dict(result)
|
||||
|
||||
print(f"[Community API] ES 搜索成功: 返回 {result.get('hits', {}).get('total', {})} 条结果")
|
||||
|
||||
return jsonify(result)
|
||||
@@ -1310,7 +1326,13 @@ def es_search_proxy(index):
|
||||
print(f"[Community API] ES 搜索失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return api_error(f'搜索失败: {str(e)}', 500)
|
||||
# 返回更详细的错误信息
|
||||
return jsonify({
|
||||
'error': str(e),
|
||||
'type': type(e).__name__,
|
||||
'index': index,
|
||||
'body': body if 'body' in dir() else None
|
||||
}), 500
|
||||
|
||||
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user