97 lines
3.1 KiB
Bash
97 lines
3.1 KiB
Bash
#!/bin/bash
|
|
# 初始化价值论坛 Elasticsearch 索引
|
|
# 使用 Nginx 代理或直连 ES
|
|
|
|
set -e
|
|
|
|
echo "🚀 开始初始化价值论坛 Elasticsearch 索引..."
|
|
echo ""
|
|
|
|
# ES 地址(根据环境选择)
|
|
if [ -n "$USE_PROXY" ]; then
|
|
ES_URL="https://valuefrontier.cn/es-api"
|
|
echo "📡 使用 Nginx 代理: $ES_URL"
|
|
else
|
|
ES_URL="http://222.128.1.157:19200"
|
|
echo "📡 直连 Elasticsearch: $ES_URL"
|
|
fi
|
|
echo ""
|
|
|
|
# 1. 创建帖子索引
|
|
echo "📝 创建帖子索引 (forum_posts)..."
|
|
curl -X PUT "$ES_URL/forum_posts" -H 'Content-Type: application/json' -d '{
|
|
"mappings": {
|
|
"properties": {
|
|
"id": { "type": "keyword" },
|
|
"author_id": { "type": "keyword" },
|
|
"author_name": { "type": "text" },
|
|
"author_avatar": { "type": "keyword" },
|
|
"title": { "type": "text" },
|
|
"content": { "type": "text" },
|
|
"images": { "type": "keyword" },
|
|
"tags": { "type": "keyword" },
|
|
"category": { "type": "keyword" },
|
|
"likes_count": { "type": "integer" },
|
|
"comments_count": { "type": "integer" },
|
|
"views_count": { "type": "integer" },
|
|
"created_at": { "type": "date" },
|
|
"updated_at": { "type": "date" },
|
|
"is_pinned": { "type": "boolean" },
|
|
"status": { "type": "keyword" }
|
|
}
|
|
}
|
|
}' 2>/dev/null && echo "✅ 帖子索引创建成功" || echo "⚠️ 帖子索引已存在或创建失败"
|
|
echo ""
|
|
|
|
# 2. 创建评论索引
|
|
echo "💬 创建评论索引 (forum_comments)..."
|
|
curl -X PUT "$ES_URL/forum_comments" -H 'Content-Type: application/json' -d '{
|
|
"mappings": {
|
|
"properties": {
|
|
"id": { "type": "keyword" },
|
|
"post_id": { "type": "keyword" },
|
|
"author_id": { "type": "keyword" },
|
|
"author_name": { "type": "text" },
|
|
"author_avatar": { "type": "keyword" },
|
|
"content": { "type": "text" },
|
|
"parent_id": { "type": "keyword" },
|
|
"likes_count": { "type": "integer" },
|
|
"created_at": { "type": "date" },
|
|
"status": { "type": "keyword" }
|
|
}
|
|
}
|
|
}' 2>/dev/null && echo "✅ 评论索引创建成功" || echo "⚠️ 评论索引已存在或创建失败"
|
|
echo ""
|
|
|
|
# 3. 创建事件时间轴索引
|
|
echo "⏰ 创建事件时间轴索引 (forum_events)..."
|
|
curl -X PUT "$ES_URL/forum_events" -H 'Content-Type: application/json' -d '{
|
|
"mappings": {
|
|
"properties": {
|
|
"id": { "type": "keyword" },
|
|
"post_id": { "type": "keyword" },
|
|
"event_type": { "type": "keyword" },
|
|
"title": { "type": "text" },
|
|
"description": { "type": "text" },
|
|
"source": { "type": "keyword" },
|
|
"source_url": { "type": "keyword" },
|
|
"related_stocks": { "type": "keyword" },
|
|
"occurred_at": { "type": "date" },
|
|
"created_at": { "type": "date" },
|
|
"importance": { "type": "keyword" }
|
|
}
|
|
}
|
|
}' 2>/dev/null && echo "✅ 事件时间轴索引创建成功" || echo "⚠️ 事件时间轴索引已存在或创建失败"
|
|
echo ""
|
|
|
|
# 4. 验证索引
|
|
echo "🔍 验证已创建的索引..."
|
|
curl -X GET "$ES_URL/_cat/indices/forum_*?v" 2>/dev/null
|
|
echo ""
|
|
|
|
echo "🎉 初始化完成!"
|
|
echo ""
|
|
echo "下一步:"
|
|
echo " 1. 访问 https://valuefrontier.cn/value-forum"
|
|
echo " 2. 点击"发布帖子"按钮创建第一篇帖子"
|