Skip to content

Commit b839db4

Browse files
committed
Finally able to add HTTP HEAD, to be able to test if index exists
1 parent 2894e5c commit b839db4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/elasticsearch/elasticsearch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ long unsigned int ElasticSearch::getDocumentCount(const char* index, const char*
162162
return pos;
163163
}
164164

165+
// Test if index exists
166+
bool ElasticSearch::exist(const std::string& index){
167+
return (200 == _http.head(index.c_str(), 0, 0));
168+
}
169+
165170
// Test if document exists
166171
bool ElasticSearch::exist(const std::string& index, const std::string& type, const std::string& id){
167172
std::stringstream url;

src/elasticsearch/elasticsearch.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class ElasticSearch {
3434
/// Delete the document by index/type.
3535
bool deleteAll(const char* index, const char* type);
3636

37-
/// Test if document exists
37+
/// Test if index exists
38+
bool exist(const std::string& index);
39+
40+
/// Test if document exists
3841
bool exist(const std::string& index, const std::string& type, const std::string& id);
3942

4043
/// Get Id of document

src/http/http.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class HTTP {
8686
return request("GET", endUrl, data, root, result);
8787
}
8888

89+
/// Generic head request to node.
90+
inline unsigned int head(const char* endUrl, const char* data, Json::Object* root){
91+
Result result;
92+
return request("HEAD", endUrl, data, root, result);
93+
}
94+
8995
/// Generic put request to node.
9096
inline unsigned int put(const char* endUrl, const char* data, Json::Object* root){
9197
Result result;

0 commit comments

Comments
 (0)