Skip to content

Commit 8a6c0a9

Browse files
jaggu-snorrvktr
authored andcommitted
Added --dump-index-info which will call /<index> to get settings and mappings
1 parent 3ae95c8 commit 8a6c0a9

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

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

7374
#### Authentication
7475

src/blaze.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,53 @@ int dump_mappings(
357357
return 0;
358358
}
359359

360+
int dump_index_info(
361+
std::string const& host,
362+
std::string const& index,
363+
auth_options const& auth)
364+
{
365+
static char write_buffer[WRITE_BUF_SIZE];
366+
static rapidjson::FileWriteStream stream(stdout, write_buffer, sizeof(write_buffer));
367+
368+
CURL * crl = curl_easy_init();
369+
long response_code;
370+
rapidjson::Document doc;
371+
std::string url = host + "/" + index;
372+
std::string error;
373+
std::vector<char> buffer;
374+
375+
bool res = get_or_post_data(
376+
crl,
377+
url,
378+
auth,
379+
&buffer,
380+
&response_code,
381+
&error);
382+
383+
if (!res)
384+
{
385+
std::cerr << "A HTTP error occured: " << error << std::endl;
386+
return 1;
387+
}
388+
389+
doc.Parse(buffer.data(), buffer.size());
390+
391+
if (doc.HasParseError())
392+
{
393+
output_parser_error(doc, std::cerr);
394+
return 1;
395+
}
396+
397+
rapidjson::Writer<rapidjson::FileWriteStream> writer(stream);
398+
doc[index.c_str()].Accept(writer);
399+
stream.Put('\n');
400+
stream.Flush();
401+
402+
curl_easy_cleanup(crl);
403+
404+
return 0;
405+
}
406+
360407
int main(
361408
int argc,
362409
char * argv[])
@@ -411,6 +458,13 @@ int main(
411458
index,
412459
auth);
413460
}
461+
else if (cmdl["--dump-index-info"])
462+
{
463+
return dump_index_info(
464+
host,
465+
index,
466+
auth);
467+
}
414468

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

0 commit comments

Comments
 (0)