功能 : 文檔存儲 與 文檔搜索
特點:比如有一個文檔名 “你好”
可以用‘你‘,'好','你好'都可以搜索到這個文檔
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
?
?