个股论坛重做
This commit is contained in:
@@ -1300,12 +1300,16 @@ def es_search_proxy(index):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
|
print(f"[Community API] ES 搜索请求: index={index}, body={body}")
|
||||||
result = es_client.search(index=index, body=body)
|
result = es_client.search(index=index, body=body)
|
||||||
|
print(f"[Community API] ES 搜索成功: 返回 {result.get('hits', {}).get('total', {})} 条结果")
|
||||||
|
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[Community API] ES 搜索失败: {e}")
|
print(f"[Community API] ES 搜索失败: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
return api_error(f'搜索失败: {str(e)}', 500)
|
return api_error(f'搜索失败: {str(e)}', 500)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -111,37 +111,35 @@ export const getMessages = async (
|
|||||||
const { before, after, limit = 50 } = options;
|
const { before, after, limit = 50 } = options;
|
||||||
|
|
||||||
// 构建 ES 查询
|
// 构建 ES 查询
|
||||||
const query: any = {
|
// 只查询主消息(非讨论串消息)
|
||||||
bool: {
|
const filters: any[] = [
|
||||||
must: [
|
{ term: { channel_id: channelId } },
|
||||||
{ term: { channel_id: channelId } },
|
];
|
||||||
{ term: { is_deleted: false } },
|
|
||||||
],
|
|
||||||
must_not: [
|
|
||||||
{ exists: { field: 'thread_id' } }, // 排除讨论串消息
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// 分页游标
|
// 分页游标
|
||||||
if (before) {
|
if (before) {
|
||||||
query.bool.must.push({
|
filters.push({ range: { created_at: { lt: before } } });
|
||||||
range: { created_at: { lt: before } },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (after) {
|
if (after) {
|
||||||
query.bool.must.push({
|
filters.push({ range: { created_at: { gt: after } } });
|
||||||
range: { created_at: { gt: after } },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const query: any = {
|
||||||
|
bool: {
|
||||||
|
filter: filters,
|
||||||
|
must_not: [
|
||||||
|
{ term: { is_deleted: true } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// 查询时总是按时间降序获取(最新的在前)
|
// 查询时总是按时间降序获取(最新的在前)
|
||||||
const response = await fetch(`${ES_API_BASE}/community_messages/_search`, {
|
const response = await fetch(`${ES_API_BASE}/community_messages/_search`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
query,
|
query,
|
||||||
sort: [{ created_at: 'desc' }],
|
sort: [{ created_at: { order: 'desc' } }],
|
||||||
size: limit,
|
size: limit,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user