Elasticlient
Classes | Public Types | Public Member Functions | List of all members
elasticlient::Client Class Reference

Class for managing Elasticsearch connection in one Elasticsearch cluster. More...

#include <client.h>

Classes

struct  ClientOption
 Abstract class for various options passed to Client constructor. More...
 
struct  ClientOptionValue
 Helper class holding single value for ClientOption implementations. More...
 
struct  ConnectTimeoutOption
 The connection timeout [ms] for client. More...
 
struct  ProxiesOption
 Proxies option for client connection. More...
 
struct  SSLOption
 Options to setup SSL for client connection. More...
 
struct  TimeoutOption
 The timeout [ms] setting for client connection. More...
 

Public Types

enum  HTTPMethod {
  GET = 0, POST = 1, PUT = 2, DELETE = 3,
  HEAD = 4
}
 Enum for kinds of supported HTTP methods in performRequest.
 

Public Member Functions

 Client (const std::vector< std::string > &hostUrlList, std::int32_t timeout=6000)
 
 Client (const std::vector< std::string > &hostUrlList, std::int32_t timeout, const std::initializer_list< std::pair< const std::string, std::string >> &proxyUrlList)
 
template<typename... Opts>
 Client (const std::vector< std::string > &hostUrlList, Opts &&... opts)
 
 Client (Client &&)
 
void setClientOption (const ClientOption &opt)
 
cpr::Response performRequest (HTTPMethod method, const std::string &urlPath, const std::string &body)
 
cpr::Response search (const std::string &indexName, const std::string &docType, const std::string &body, const std::string &routing=std::string())
 
cpr::Response get (const std::string &indexName, const std::string &docType, const std::string &id=std::string(), const std::string &routing=std::string())
 
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())
 
cpr::Response remove (const std::string &indexName, const std::string &docType, const std::string &id, const std::string &routing=std::string())
 

Detailed Description

Class for managing Elasticsearch connection in one Elasticsearch cluster.

Constructor & Destructor Documentation

◆ Client() [1/3]

elasticlient::Client::Client ( const std::vector< std::string > &  hostUrlList,
std::int32_t  timeout = 6000 
)
explicit

Initialize the Client.

Parameters
hostUrlListVector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should ends by "/".
timeoutElastic node connection timeout.

◆ Client() [2/3]

elasticlient::Client::Client ( const std::vector< std::string > &  hostUrlList,
std::int32_t  timeout,
const std::initializer_list< std::pair< const std::string, std::string >> &  proxyUrlList 
)
explicit

Initialize the Client.

Parameters
hostUrlListVector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should end by "/".
timeoutElastic node connection timeout.
proxyUrlListList of used HTTP proxies.

◆ Client() [3/3]

template<typename... Opts>
elasticlient::Client::Client ( const std::vector< std::string > &  hostUrlList,
Opts &&...  opts 
)
inline

Initialize the Client.

Variadic arguments derived from ClientOption can be passed to it. The later option overwrites the preceeding one for same object types passed into it.

Parameters
hostUrlListVector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should end by "/".

Member Function Documentation

◆ get()

cpr::Response elasticlient::Client::get ( const std::string &  indexName,
const std::string &  docType,
const std::string &  id = std::string(),
const std::string &  routing = std::string() 
)

Get document with specified id from cluster. Throws exception if all nodes has failed to respond.

Parameters
indexNamespecification of an Elasticsearch index.
docTypespecification of an Elasticsearch document type.
idId of document which should be retrieved.
routingElasticsearch routing. If empty, no routing has been used.
Returns
cpr::Response if any of node responds to request.
Exceptions
ConnectionExceptionif all hosts in cluster failed to respond.

◆ index()

cpr::Response elasticlient::Client::index ( const std::string &  indexName,
const std::string &  docType,
const std::string &  id,
const std::string &  body,
const std::string &  routing = std::string() 
)

Index new document to cluster. Throws exception if all nodes has failed to respond.

Parameters
indexNamespecification of an Elasticsearch index.
docTypespecification of an Elasticsearch document type.
bodyElasticsearch request body.
idId of document which should be indexed. If empty, id will be generated automatically by Elasticsearch cluster.
routingElasticsearch routing. If empty, no routing has been used.
Returns
cpr::Response if any of node responds to request.
Exceptions
ConnectionExceptionif all hosts in cluster failed to respond.

◆ performRequest()

cpr::Response elasticlient::Client::performRequest ( HTTPMethod  method,
const std::string &  urlPath,
const std::string &  body 
)

Perform request on nodes until it is successful. Throws exception if all nodes has failed to respond.

Parameters
methodone of Client::HTTPMethod.
urlPathpart of URL immediately behind "scheme://host/".
bodyElasticsearch request body.
Returns
cpr::Response if any of node responds to request.
Exceptions
ConnectionExceptionif all hosts in cluster failed to respond.

◆ remove()

cpr::Response elasticlient::Client::remove ( const std::string &  indexName,
const std::string &  docType,
const std::string &  id,
const std::string &  routing = std::string() 
)

Delete document with specified id from cluster. Throws exception if all nodes has failed to respond.

Parameters
indexNamespecification of an Elasticsearch index.
docTypespecification of an Elasticsearch document type.
idId of document which should be deleted.
routingElasticsearch routing. If empty, no routing has been used.
Returns
cpr::Response if any of node responds to request.
Exceptions
ConnectionExceptionif all hosts in cluster failed to respond.

◆ search()

cpr::Response elasticlient::Client::search ( const std::string &  indexName,
const std::string &  docType,
const std::string &  body,
const std::string &  routing = std::string() 
)

Perform search on nodes until it is successful. Throws exception if all nodes has failed to respond.

Parameters
indexNamespecification of an Elasticsearch index.
docTypespecification of an Elasticsearch document type.
bodyElasticsearch request body.
routingElasticsearch routing. If empty, no routing has been used.
Returns
cpr::Response if any of node responds to request.
Exceptions
ConnectionExceptionif all hosts in cluster failed to respond.

◆ setClientOption()

void elasticlient::Client::setClientOption ( const ClientOption opt)

Set single option derived from ClientOption to the client.

Parameters
optOption to set. Has to be base of ClientOption.

The documentation for this class was generated from the following file: