Elasticlient
C++ elasticlient library

C++ elasticlient library is simple library for simplified work with Elasticsearch in C++.

You can find some basic information - how to build library and how to use it in Readme.md file.

Provided features

Major provided classes

Helper functions

Helper enumerations

How to use the library

#include <string>
#include <vector>
#include <iostream>
#include <cpr/response.h>
int main() {
// Prepare Client for nodes of one Elasticsearch cluster
elasticlient::Client client({"http://elastic1.host:9200/"}); // last / is mandatory
std::string document {"{\"message\": \"Hello world!\"}"};
// Index the document, index "testindex" must be created before
cpr::Response indexResponse = client.index("testindex", "docType", "docId", document);
// 200
std::cout << indexResponse.status_code << std::endl;
// application/json; charset=UTF-8
std::cout << indexResponse.header["content-type"] << std::endl;
// Elasticsearch response (JSON text string)
std::cout << indexResponse.text << std::endl;
// Retrieve the document
cpr::Response retrievedDocument = client.get("testindex", "docType", "docId");
// 200
std::cout << retrievedDocument.status_code << std::endl;
// application/json; charset=UTF-8
std::cout << retrievedDocument.header["content-type"] << std::endl;
// Elasticsearch response (JSON text string) where key "_source" contain:
// {"message": "Hello world!"}
std::cout << retrievedDocument.text << std::endl;
// Remove the document
cpr::Response removedDocument = client.remove("testindex", "docType", "docId");
// 200
std::cout << removedDocument.status_code << std::endl;
// application/json; charset=UTF-8
std::cout << removedDocument.header["content-type"] << std::endl;
// Elasticsearch response (JSON text string)
std::cout << removedDocument.text << std::endl;
return 0;
}

You can also find this and more examples of basic usage of library here.

Templated version of the constructor elasticlient::Client::Client accepts option arguments to set timeout, proxy servers or SSL. Just pass these instances to it in any order (just after vector of cluster nodes):

elasticlient::Client::index
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())
elasticlient::Client
Class for managing Elasticsearch connection in one Elasticsearch cluster.
Definition: client.h:35
client.h