Class for managing Elasticsearch connection in one Elasticsearch cluster.
More...
#include <client.h>
|
enum | HTTPMethod {
GET = 0,
POST = 1,
PUT = 2,
DELETE = 3,
HEAD = 4
} |
| Enum for kinds of supported HTTP methods in performRequest.
|
|
|
| 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()) |
|
Class for managing Elasticsearch connection in one Elasticsearch cluster.
◆ Client() [1/3]
elasticlient::Client::Client |
( |
const std::vector< std::string > & |
hostUrlList, |
|
|
std::int32_t |
timeout = 6000 |
|
) |
| |
|
explicit |
Initialize the Client.
- Parameters
-
hostUrlList | Vector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should ends by "/". |
timeout | Elastic 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
-
hostUrlList | Vector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should end by "/". |
timeout | Elastic node connection timeout. |
proxyUrlList | List 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
-
hostUrlList | Vector of URLs of Elasticsearch nodes in one Elasticsearch cluster. Each URL in vector should end by "/". |
◆ 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
-
indexName | specification of an Elasticsearch index. |
docType | specification of an Elasticsearch document type. |
id | Id of document which should be retrieved. |
routing | Elasticsearch routing. If empty, no routing has been used. |
- Returns
- cpr::Response if any of node responds to request.
- Exceptions
-
◆ 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
-
indexName | specification of an Elasticsearch index. |
docType | specification of an Elasticsearch document type. |
body | Elasticsearch request body. |
id | Id of document which should be indexed. If empty, id will be generated automatically by Elasticsearch cluster. |
routing | Elasticsearch routing. If empty, no routing has been used. |
- Returns
- cpr::Response if any of node responds to request.
- Exceptions
-
◆ 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
-
method | one of Client::HTTPMethod. |
urlPath | part of URL immediately behind "scheme://host/". |
body | Elasticsearch request body. |
- Returns
- cpr::Response if any of node responds to request.
- Exceptions
-
◆ 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
-
indexName | specification of an Elasticsearch index. |
docType | specification of an Elasticsearch document type. |
id | Id of document which should be deleted. |
routing | Elasticsearch routing. If empty, no routing has been used. |
- Returns
- cpr::Response if any of node responds to request.
- Exceptions
-
◆ 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
-
indexName | specification of an Elasticsearch index. |
docType | specification of an Elasticsearch document type. |
body | Elasticsearch request body. |
routing | Elasticsearch routing. If empty, no routing has been used. |
- Returns
- cpr::Response if any of node responds to request.
- Exceptions
-
◆ setClientOption()
void elasticlient::Client::setClientOption |
( |
const ClientOption & |
opt | ) |
|
Set single option derived from ClientOption to the client.
- Parameters
-
The documentation for this class was generated from the following file:
- /home/runner/work/elasticlient/elasticlient/include/elasticlient/client.h