This commit is contained in:
2025-10-13 18:34:48 +08:00
commit 37865d041f
116 changed files with 31168 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#include "../../../common/data_es.hpp"
#include <gflags/gflags.h>
DEFINE_bool(run_mode, false, "程序的运行模式false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下,用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下,用于指定日志输出等级");
DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");
int main(int argc, char *argv[])
{
google::ParseCommandLineFlags(&argc, &argv, true);
bite_im::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);
auto es_client = bite_im::ESClientFactory::create({FLAGS_es_host});
auto es_msg = std::make_shared<bite_im::ESMessage>(es_client);
// es_msg->createIndex();
// es_msg->appendData("用户ID1", "消息ID1", 1723025035, "会话ID1", "吃饭了吗?");
// es_msg->appendData("用户ID2", "消息ID2", 1723025035 - 100, "会话ID1", "吃的盖浇饭!");
// es_msg->appendData("用户ID3", "消息ID3", 1723025035, "会话ID2", "吃饭了吗?");
// es_msg->appendData("用户ID4", "消息ID4", 1723025035 - 100, "会话ID2", "吃的盖浇饭!");
auto res = es_msg->search("盖浇", "会话ID1");
for (auto &u : res) {
std::cout << "-----------------" << std::endl;
std::cout << u.user_id() << std::endl;
std::cout << u.message_id() << std::endl;
std::cout << u.session_id() << std::endl;
std::cout << boost::posix_time::to_simple_string(u.create_time()) << std::endl;
std::cout << u.content() << std::endl;
}
return 0;
}

View File

@ -0,0 +1,72 @@
POST /message/_doc
{
"settings" : {
"analysis" : {
"analyzer" : {
"ik" : {
"tokenizer" : "ik_max_word"
}
}
}
},
"mappings" : {
"dynamic" : true,
"properties" : {
"chat_session_id" : {
"type" : "keyword",
"analyzer" : "standard"
},
"message_id" : {
"type" : "keyword",
"analyzer" : "standard"
},
"content" : {
"type" : "text",
"analyzer" : "ik_max_word"
}
}
}
}
GET /message/_doc/_search?pretty
{
"query": {
"match_all": {}
}
}
POST /message/_doc/_bulk
{"index":{"_id":"1"}}
{"chat_session_id" : "会话ID1","message_id" : "消息ID1","content" : "吃饭了么?"}
{"index":{"_id":"2"}}
{"chat_session_id" : "会话ID1","message_id" : "消息ID2","content" : "吃的盖浇饭。"}
{"index":{"_id":"3"}}
{"chat_session_id" : "会话ID2","message_id" : "消息ID3","content" : "昨天吃饭了么?"}
{"index":{"_id":"4"}}
{"chat_session_id" : "会话ID2","message_id" : "消息ID4","content" : "昨天吃的盖浇饭。"}
GET /message/_doc/_search?pretty
{
"query": {
"bool": {
"must": [
{
"term": {
"chat_session_id.keyword": "会话ID1"
}
},
{
"match": {
"content": "盖浇饭"
}
}
]
}
}
}
DELETE /message