#!/bin/bash # 社区模块 ES 索引重建脚本 # 执行方式: bash es_rebuild_all.sh ES_HOST="http://222.128.1.157:19200" echo "=== 1. 删除旧索引 ===" curl -X DELETE "$ES_HOST/community_forum_posts" 2>/dev/null; echo "" curl -X DELETE "$ES_HOST/community_forum_replies" 2>/dev/null; echo "" curl -X DELETE "$ES_HOST/community_messages" 2>/dev/null; echo "" curl -X DELETE "$ES_HOST/community_notifications" 2>/dev/null; echo "" echo "" echo "=== 2. 创建帖子索引 community_forum_posts ===" curl -X PUT "$ES_HOST/community_forum_posts" -H "Content-Type: application/json" -d ' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "channel_id": { "type": "keyword" }, "author_id": { "type": "keyword" }, "author_name": { "type": "keyword" }, "author_avatar": { "type": "keyword" }, "title": { "type": "text" }, "content": { "type": "text" }, "content_html": { "type": "text", "index": false }, "tags": { "type": "keyword" }, "stock_symbols": { "type": "keyword" }, "is_pinned": { "type": "boolean" }, "is_locked": { "type": "boolean" }, "is_deleted": { "type": "boolean" }, "reply_count": { "type": "integer" }, "view_count": { "type": "integer" }, "like_count": { "type": "integer" }, "last_reply_at": { "type": "date" }, "last_reply_by": { "type": "keyword" }, "created_at": { "type": "date" }, "updated_at": { "type": "date" } } } }' echo "" echo "" echo "=== 3. 创建回复索引 community_forum_replies ===" curl -X PUT "$ES_HOST/community_forum_replies" -H "Content-Type: application/json" -d ' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "post_id": { "type": "keyword" }, "channel_id": { "type": "keyword" }, "author_id": { "type": "keyword" }, "author_name": { "type": "keyword" }, "author_avatar": { "type": "keyword" }, "content": { "type": "text" }, "content_html": { "type": "text", "index": false }, "reply_to": { "type": "object", "enabled": false }, "reactions": { "type": "object", "enabled": false }, "like_count": { "type": "integer" }, "is_solution": { "type": "boolean" }, "is_deleted": { "type": "boolean" }, "created_at": { "type": "date" } } } }' echo "" echo "" echo "=== 4. 创建消息索引 community_messages ===" curl -X PUT "$ES_HOST/community_messages" -H "Content-Type: application/json" -d ' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "channel_id": { "type": "keyword" }, "author_id": { "type": "keyword" }, "author_name": { "type": "keyword" }, "author_avatar": { "type": "keyword" }, "content": { "type": "text" }, "content_html": { "type": "text", "index": false }, "mentioned_users": { "type": "keyword" }, "mentioned_stocks": { "type": "keyword" }, "attachments": { "type": "object", "enabled": false }, "embeds": { "type": "object", "enabled": false }, "reactions": { "type": "object", "enabled": false }, "reply_to": { "type": "object", "enabled": false }, "thread_id": { "type": "keyword" }, "is_pinned": { "type": "boolean" }, "is_edited": { "type": "boolean" }, "is_deleted": { "type": "boolean" }, "created_at": { "type": "date" }, "updated_at": { "type": "date" } } } }' echo "" echo "" echo "=== 5. 创建通知索引 community_notifications ===" curl -X PUT "$ES_HOST/community_notifications" -H "Content-Type: application/json" -d ' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "user_id": { "type": "keyword" }, "type": { "type": "keyword" }, "title": { "type": "text" }, "content": { "type": "text" }, "content_html": { "type": "text", "index": false }, "from_user_id": { "type": "keyword" }, "from_user_name": { "type": "keyword" }, "from_user_avatar": { "type": "keyword" }, "related_id": { "type": "keyword" }, "related_type": { "type": "keyword" }, "channel_id": { "type": "keyword" }, "is_read": { "type": "boolean" }, "created_at": { "type": "date" } } } }' echo "" echo "" echo "=== 完成!验证索引 ===" curl -X GET "$ES_HOST/_cat/indices/community_*?v"