当前位置: 首页 > news >正文

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

相关文章:

  • 【量化策略】动量追踪策略
  • Tkinter 标准对话框
  • 【PromptCoder】使用 package.json 生成 cursorrules
  • AWS S3 如何设置公开访问权限?
  • Git系列详细介绍和操作
  • Flutter系列教程之(5)——常用控件Widget的使用示例
  • 深入理解 Spring 中的 `ThreadPoolTaskExecutor` 与 `ThreadPoolExecutor`
  • CC攻击防御策略全解析:技术实现与代码示例
  • 【C/C++】理解C++内存与Linux虚拟地址空间的关系---带你通透C++中所有数据
  • 【堆】堆的基本概念及操作,堆与优先队列
  • 航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
  • 文章表中文章内容content字段存富文本数据,在大量数据的前提下关于优化查询速度的思考
  • Docker 高级网络配置
  • 渗透测试【绕过过滤order by 、limit】
  • 用DeepSeek来帮助学习three.js加载3D太极模形
  • 无人机遥控器的亮度 和 两个工作频率
  • python中的JSON数据格式
  • android keystore源码分析
  • 代码随想录算法训练营第五十天| 动态规划12
  • centos9之ESXi环境下安装
  • 网站设计论文html/如何去除痘痘有效果
  • html5网站后台模板怎么调用前台/汕尾网站seo
  • 重庆 网站设计/百度指数api
  • 安阳网站建设公司/今日新闻头条官网
  • 东营注册公司/香港seo公司
  • 宁波网站开发公司电话/百度客服人工电话24小时