ES的简单讲解

功能 : 文档存储 与 文档搜索

特点:比如有一个文档名 "你好"

可以用'你','好','你好'都可以搜索到这个文档

ES核心概念

类似于数据库中表的概念,在表的概念下又对数据集合进行了细分

​

ES_Client查询接口

cpr::Response search(const std::string &indexName,

const std::string &docType,

const std::string &body,

const std::string &routing = std::string());

indexName:索引名称

docType:类型几乎弃用 _doc 填入

body: 请求正文 数据操作json字符串

创建与新增索引

cpr::Response index(const std::string &indexName,

const std::string &docType,

const std::string &id,

const std::string &body,

const std::string &routing = std::string());

indexName:索引名称

docType:类型几乎弃用 _doc 填入

id:数据ID 可以自己指定唯一数也可以被es生成

body:创建索引的json正文

删除

cpr::Response remove(const std::string &indexName,

const std::string &docType,

const std::string &id,

const std::string &routing = std::string());

具体的操作

Response

我们需要获取状态码与其他的一些响应

​

status_code 状态码

text 响应正文

9200

复制代码
#include <elasticlient/client.h>
#include <cpr/response.h>
#include <iostream>

int main()
{
    elasticlient::Client client({"http://127.0.0.1:9200/"});
    try
    {
        // auto resp=client.search("usr","_doc",  "{\"query\": { \"match_all\":{} } }");
        std::string search_body = R"({"query": { "match_all":
{} } })";

        cpr::Response retrievedDocument = client.search(
            "user", "_doc", search_body);
        std::cout << retrievedDocument.status_code << std::endl;

        std::cout << retrievedDocument.text << std::endl;
    }
    catch (const std::exception &e)
    {
        std::cerr << e.what() << '\n';
    }
}

json 序列化与反序列化

以明文字符窜进行数据组织 --- 容易看懂

以键值对信息进行组织

{

"姓名":"张三",

"年龄": 88 ,

"成绩": 100,98,98

}

json:Value

数据进行序列化时,需要将数据存储到Value中,再对Value进行序列化

operator\[\] : Value"姓名"="张三"

​

对数组进行新增 Value"成绩".append(88)​

​

Value"姓名".asString()

​

通过下边访问数组

Value"成绩"1

​

​

Writer类

将Value类进行序列化输出到一个流中

​

writer的工厂类

​ ​

​

​

​Reader

​

反序列化函数

​

工厂类

​​

newCharReader类 返回一个CharReader

​

​

相关推荐
ShineWinsu3 小时前
对于Qt:事件的解析
c++·qt·面试·笔试·gui·客户端·事件
闻缺陷则喜何志丹5 小时前
【数论】P10136 [USACO24JAN] Cowlendar S|普及+
c++·数学·数论·洛谷
apcipot_rain6 小时前
某游戏公司C++游开实习 机试复盘
c++·游戏
云起无垠8 小时前
关掉笔记本,让 AI agent 在远程服务器上继续跑完一夜:DevAgent 的 SSH 远程工作区实战
服务器·人工智能·ssh
炸膛坦客8 小时前
单片机/C/C++八股:(三十七)指针数组 和 数组指针
c语言·开发语言·c++
夜不会漫长8 小时前
C++:C++11特性
开发语言·c++·算法
无足鸟ICT9 小时前
【RHCA+】_proc_pid_task_
linux·运维·服务器
星恒随风11 小时前
从0实现C++ AI大模型接入SDK(五):DeepSeekProvider的实现——策略模式、HTTP请求与SSE流式响应
linux·开发语言·c++·人工智能
weixin_4046793111 小时前
cc 在 linux 安装
linux·运维·服务器
贞明电子12 小时前
贞明电子网口设备 Modbus TCP 工业接入实战指南
服务器·网络协议·tcp/ip·贞明电子