Elasticlient
bulk.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 #include <cstdint>
12 
13 
15 namespace elasticlient {
16 
17 
18 // Forward Client class existence.
19 class Client;
20 
21 
23 class IBulkData {
24  public:
25  virtual ~IBulkData();
26 
31  virtual std::string indexName() const = 0;
32 
34  virtual bool empty() const = 0;
35 
37  virtual std::size_t size() const = 0;
38 
40  virtual std::string body() const = 0;
41 };
42 
43 
50  class Implementation;
51  std::unique_ptr<Implementation> impl;
52 
53  public:
60  explicit SameIndexBulkData(const std::string &indexName, std::size_t size = 100);
62 
64  virtual std::string indexName() const override;
65 
73  bool indexDocument(const std::string &docType,
74  const std::string &id,
75  const std::string &doc);
76 
86  bool indexDocument(const std::string &docType,
87  const std::string &id,
88  const std::string &doc,
89  bool validate);
90 
98  bool createDocument(const std::string &docType,
99  const std::string &id,
100  const std::string &doc);
101 
111  bool createDocument(const std::string &docType,
112  const std::string &id,
113  const std::string &doc,
114  bool validate);
115 
123  bool updateDocument(
124  const std::string &docType,
125  const std::string &id,
126  const std::string &doc);
127 
137  bool updateDocument(
138  const std::string &docType,
139  const std::string &id,
140  const std::string &doc,
141  bool validate);
142 
144  void clear();
145 
147  virtual bool empty() const override;
148 
150  virtual std::size_t size() const override;
151 
153  virtual std::string body() const override;
154 };
155 
156 
158 class Bulk {
159  class Implementation;
160  std::unique_ptr<Implementation> impl;
161 
162  public:
167  Bulk(const std::shared_ptr<Client> &client);
168 
175  Bulk(const std::vector<std::string> &hostUrlList,
176  std::int32_t connectionTimeout);
182  ~Bulk();
183 
184  Bulk(Bulk &&other);
185 
190  std::size_t perform(const IBulkData &bulk);
191 
193  std::size_t getErrorCount() const;
194 
196  const std::shared_ptr<Client> &getClient() const;
197 
198 };
199 
200 
201 } // namespace elasticlient
elasticlient::IBulkData::body
virtual std::string body() const =0
Return elasticsearch bulk request data.
elasticlient::Bulk::perform
std::size_t perform(const IBulkData &bulk)
elasticlient::Bulk::getErrorCount
std::size_t getErrorCount() const
Return number of errors in last bulk being ran.
elasticlient::IBulkData
Interface for Bulk data collector classes.
Definition: bulk.h:23
elasticlient::SameIndexBulkData::body
virtual std::string body() const override
Return elasticsearch bulk request data.
elasticlient::SameIndexBulkData::createDocument
bool createDocument(const std::string &docType, const std::string &id, const std::string &doc)
elasticlient::Bulk::Bulk
Bulk(const std::shared_ptr< Client > &client)
elasticlient::Bulk::~Bulk
~Bulk()
elasticlient::SameIndexBulkData
Definition: bulk.h:49
elasticlient::SameIndexBulkData::SameIndexBulkData
SameIndexBulkData(const std::string &indexName, std::size_t size=100)
elasticlient::Bulk::getClient
const std::shared_ptr< Client > & getClient() const
Return Client class with current config.
elasticlient::Bulk
Class for bulk document indexing.
Definition: bulk.h:158
elasticlient
The elasticlient namespace.
Definition: bulk.h:15
elasticlient::SameIndexBulkData::empty
virtual bool empty() const override
Return true if bulk has no data inside.
elasticlient::SameIndexBulkData::indexDocument
bool indexDocument(const std::string &docType, const std::string &id, const std::string &doc)
elasticlient::SameIndexBulkData::indexName
virtual std::string indexName() const override
Return index name set during contruction.
elasticlient::SameIndexBulkData::clear
void clear()
Clear bulk (size() == 0 after this).
elasticlient::SameIndexBulkData::size
virtual std::size_t size() const override
Return number of documents inside the bulk.
elasticlient::IBulkData::size
virtual std::size_t size() const =0
Return number of documents inside the bulk.
elasticlient::SameIndexBulkData::updateDocument
bool updateDocument(const std::string &docType, const std::string &id, const std::string &doc)
elasticlient::IBulkData::empty
virtual bool empty() const =0
Return true if bulk has no data inside.
elasticlient::IBulkData::indexName
virtual std::string indexName() const =0
elasticlient::Client
Class for managing Elasticsearch connection in one Elasticsearch cluster.
Definition: client.h:35