Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ RUN apk update

RUN apk add --no-cache g++ gcc automake make autoconf libtool curl-dev git

RUN git clone --recurse-submodules https://github.com/unidentifieddeveloper/blaze.git .
COPY vendor/ ./vendor
COPY src/ ./src
COPY Makefile .

RUN make

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ cat dump.ndjson | parallel --pipe -l 50000 curl -s -H "Content-Type: application
- `--size=<value>` - *(optional)* the size of the response (i.e, length of the `hits` array).
Defaults to *5000*.
- `--dump-mappings` - specify this flag to dump the index mappings instead of the source.
- `--dump-index-info` - specify this flag to dump the full index information (settings and mappings) instead of the source.

#### Authentication

Expand Down
57 changes: 54 additions & 3 deletions src/blaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,11 @@ void write_document(
{
auto meta_index = rapidjson::Value(rapidjson::kObjectType);
auto meta_index_id = rapidjson::Value();
auto meta_index_type = rapidjson::Value();
auto meta_object = rapidjson::Value(rapidjson::kObjectType);

meta_index_id.SetString(hit["_id"].GetString(), allocator);
meta_index_type.SetString(hit["_type"].GetString(), allocator);

meta_index.AddMember("_id", meta_index_id, allocator);
meta_index.AddMember("_type", meta_index_type, allocator);

meta_object.AddMember("index", meta_index, allocator);

Expand Down Expand Up @@ -360,6 +357,53 @@ int dump_mappings(
return 0;
}

int dump_index_info(
std::string const& host,
std::string const& index,
auth_options const& auth)
{
static char write_buffer[WRITE_BUF_SIZE];
static rapidjson::FileWriteStream stream(stdout, write_buffer, sizeof(write_buffer));

CURL * crl = curl_easy_init();
long response_code;
rapidjson::Document doc;
std::string url = host + "/" + index;
std::string error;
std::vector<char> buffer;

bool res = get_or_post_data(
crl,
url,
auth,
&buffer,
&response_code,
&error);

if (!res)
{
std::cerr << "A HTTP error occured: " << error << std::endl;
return 1;
}

doc.Parse(buffer.data(), buffer.size());

if (doc.HasParseError())
{
output_parser_error(doc, std::cerr);
return 1;
}

rapidjson::Writer<rapidjson::FileWriteStream> writer(stream);
doc[index.c_str()].Accept(writer);
stream.Put('\n');
stream.Flush();

curl_easy_cleanup(crl);

return 0;
}

int main(
int argc,
char * argv[])
Expand Down Expand Up @@ -414,6 +458,13 @@ int main(
index,
auth);
}
else if (cmdl["--dump-index-info"])
{
return dump_index_info(
host,
index,
auth);
}

// Sanity check - see if we have any documents in the index at all.
if (count_documents(host, index, auth) <= 0)
Expand Down