diff --git a/README.md b/README.md index 3a5c65fb..d7087969 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,15 @@ Print a list of which plugins are installed and how to install any that are miss node scripts/check_plugins.js ``` +#### check indexed documents + +Display a summary of doc counts per source/layer. By default the stats for the importing index is used. Only use `--api` if your requesting index differs from your importing index + +```bash +node scripts/check_stats.js +node scripts/check_stats.js --api +``` + ## Configuration ### Settings from `pelias.json` diff --git a/scripts/check_stats.js b/scripts/check_stats.js new file mode 100644 index 00000000..be3168f6 --- /dev/null +++ b/scripts/check_stats.js @@ -0,0 +1,50 @@ +const config = require('pelias-config').generate(); +const es = require('elasticsearch'); +const client = new es.Client(config.esclient); +const targetIndex = getTargetIndex(); + + +async function stats(targetIndex) { + try { + const response = await client.search({ + index: targetIndex, + body: { + aggs: { + sources: { + terms: { + field: 'source', + size: 100 + }, + aggs: { + layers: { + terms: { + field: "layer", + size: 100 + } + } + } + } + }, + size: 0, + }, + timeout: '10s', + request_cache: true, + maxRetries: 1, + }); + console.log("Results for index \"" + targetIndex + "\":") + console.log(JSON.stringify(response, null, 2)); + process.exit(0); + } + catch (err) { + console.error(err); + process.exit(!!err); + } +}; + +function getTargetIndex() { + if (process.argv.length > 2 && ['--api', '-a'].indexOf(process.argv[2]) > -1) { + return config.api.indexName; //If none is set the value from pelias/config/config/defaults.json will be used ('pelias') + } + return config.schema.indexName; +} +stats(targetIndex); \ No newline at end of file