Skip to content

Commit

Permalink
Added --dump-index-info which will call /<index> to get settings and …
Browse files Browse the repository at this point in the history
…mappings
  • Loading branch information
jaggu-snorr authored and vktr committed Dec 10, 2024
1 parent 3ae95c8 commit 8a6c0a9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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
54 changes: 54 additions & 0 deletions src/blaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,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 @@ -411,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

0 comments on commit 8a6c0a9

Please sign in to comment.