Skip to content

Commit bd8763b

Browse files
committed
Added functions for delete index and type
1 parent a6a7ac0 commit bd8763b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/elasticsearch/elasticsearch.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,28 @@ long ElasticSearch::search(const std::string& index, const std::string& type, co
309309
return result.getValue("hits").getObject().getValue("total").getLong();
310310
}
311311

312+
/// Delete given type (and all documents, mappings)
313+
bool ElasticSearch::deleteType(const std::string& index, const std::string& type){
314+
std::ostringstream uri;
315+
uri << index << "/" << type;
316+
return (200 == _http.remove(uri.str().c_str(), 0, 0));
317+
}
318+
312319
// Test if index exists
313320
bool ElasticSearch::exist(const std::string& index){
314321
return (200 == _http.head(index.c_str(), 0, 0));
315322
}
316323

317-
// Test if index exists
324+
// Create index, optionally with data (settings, mappings etc)
318325
bool ElasticSearch::createIndex(const std::string& index, const char* data){
319326
return (200 == _http.put(index.c_str(), data, 0));
320327
}
321328

329+
// Delete given index (and all types, documents, mappings)
330+
bool ElasticSearch::deleteIndex(const std::string& index){
331+
return (200 == _http.remove(index.c_str(), 0, 0));
332+
}
333+
322334
// Refresh the index.
323335
void ElasticSearch::refresh(const std::string& index){
324336
std::ostringstream oss;

src/elasticsearch/elasticsearch.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ class ElasticSearch {
6161
/// Perform a scan to get all results from a query.
6262
int fullScan(const std::string& index, const std::string& type, const std::string& query, Json::Array& resultArray, int scrollSize = 1000);
6363

64+
public:
65+
/// Delete given type (and all documents, mappings)
66+
bool deleteType(const std::string& index, const std::string& type);
67+
6468
public:
6569
/// Test if index exists
6670
bool exist(const std::string& index);
6771

6872
/// Create index, optionally with data (settings, mappings etc)
6973
bool createIndex(const std::string& index, const char* data = NULL);
70-
74+
75+
/// Delete given index (and all types, documents, mappings)
76+
bool deleteIndex(const std::string& index);
77+
7178
/// Refresh the index.
7279
void refresh(const std::string& index);
7380

0 commit comments

Comments
 (0)