Skip to content

Commit

Permalink
Merge pull request seznam#5 from WLBF/feature/bulk-update
Browse files Browse the repository at this point in the history
updateDocument feature for SameIndexBulkData
  • Loading branch information
mbumba authored Sep 14, 2018
2 parents 5d91a85 + c691422 commit 7ada831
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/elasticlient/bulk.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ class SameIndexBulkData: public IBulkData {
const std::string &docType, const std::string &id,
const std::string &doc);

/**
* Add update document request to the bulk.
* \param docType document type (as specified in mapping).
* \param id document ID.
* \param doc Json document to index. Must not contain newline char.
* \return true if bulk has reached its desired capacity.
*/
bool updateDocument(
const std::string &docType, const std::string &id,
const std::string &doc);

/// Clear bulk (size() == 0 after this).
void clear();

Expand Down
9 changes: 9 additions & 0 deletions src/bulk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ bool SameIndexBulkData::createDocument(
return impl->data.size() >= impl->size;
}

bool SameIndexBulkData::updateDocument(
const std::string &docType, const std::string &id, const std::string &doc)
{
validateDocument(doc, id);
impl->data.emplace_back(createControl("update", docType, id), doc);
// return true if bulk has reached its desired capacity
return impl->data.size() >= impl->size;
}


void SameIndexBulkData::clear() {
impl->data.resize(0);
Expand Down

0 comments on commit 7ada831

Please sign in to comment.