From b1ed79010a699ef2c7bc75a11aa7a2d843e6ffd6 Mon Sep 17 00:00:00 2001 From: arnesetzer <25772747+arnesetzer@users.noreply.github.com> Date: Mon, 10 Mar 2025 15:28:29 +0100 Subject: [PATCH 1/4] feat: Allow variable index names for pelias docker --- scripts/check_stats.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/check_stats.js diff --git a/scripts/check_stats.js b/scripts/check_stats.js new file mode 100644 index 00000000..c8e83e84 --- /dev/null +++ b/scripts/check_stats.js @@ -0,0 +1,41 @@ +const config = require('pelias-config').generate(); +const es = require('elasticsearch'); +const client = new es.Client(config.esclient); + +async function stats() { + try { + const response = await client.search({ + index: config.api.indexName, + 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 \""+config.api.indexName+"\":") + console.log(JSON.stringify(response, null, 2)); + process.exit(0); + } + catch (err) { + console.error(err); + process.exit(!!err); + } +} +stats(); \ No newline at end of file From 611198a960d8df5c9a933f0dab53147d5ab84737 Mon Sep 17 00:00:00 2001 From: arnesetzer <25772747+arnesetzer@users.noreply.github.com> Date: Tue, 11 Mar 2025 12:12:57 +0100 Subject: [PATCH 2/4] fix: Change requesting index to writing index --- scripts/check_stats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check_stats.js b/scripts/check_stats.js index c8e83e84..d5108e4c 100644 --- a/scripts/check_stats.js +++ b/scripts/check_stats.js @@ -5,7 +5,7 @@ const client = new es.Client(config.esclient); async function stats() { try { const response = await client.search({ - index: config.api.indexName, + index: config.schema.indexName, body: { aggs: { sources: { @@ -29,7 +29,7 @@ async function stats() { request_cache: true, maxRetries: 1, }); - console.log("Results for index \""+config.api.indexName+"\":") + console.log("Results for index \""+config.schema.indexName+"\":") console.log(JSON.stringify(response, null, 2)); process.exit(0); } From df96aa5efb5dd626b2f9d0109c57317257f49c1d Mon Sep 17 00:00:00 2001 From: arnesetzer <25772747+arnesetzer@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:38:09 +0100 Subject: [PATCH 3/4] feat: allows to change stats index with argument --- scripts/check_stats.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/check_stats.js b/scripts/check_stats.js index d5108e4c..be3168f6 100644 --- a/scripts/check_stats.js +++ b/scripts/check_stats.js @@ -1,11 +1,13 @@ const config = require('pelias-config').generate(); const es = require('elasticsearch'); const client = new es.Client(config.esclient); +const targetIndex = getTargetIndex(); -async function stats() { + +async function stats(targetIndex) { try { const response = await client.search({ - index: config.schema.indexName, + index: targetIndex, body: { aggs: { sources: { @@ -29,7 +31,7 @@ async function stats() { request_cache: true, maxRetries: 1, }); - console.log("Results for index \""+config.schema.indexName+"\":") + console.log("Results for index \"" + targetIndex + "\":") console.log(JSON.stringify(response, null, 2)); process.exit(0); } @@ -37,5 +39,12 @@ async function stats() { 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(); \ No newline at end of file +stats(targetIndex); \ No newline at end of file From 454f99f51e9b9ca839b42b3506a529949149413f Mon Sep 17 00:00:00 2001 From: arnesetzer <25772747+arnesetzer@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:38:40 +0100 Subject: [PATCH 4/4] docs: Add check_stats to readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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`