Skip to content

Commit

Permalink
fix: consolelog
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Jun 4, 2024
1 parent 2b7f9e5 commit 61c20c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
1 change: 0 additions & 1 deletion shared/elasticsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
]
},
"dependencies": {
"@shared/utils": "workspace:^",
"got": "^11.8.2"
},
"license": "Apache-2.0",
Expand Down
20 changes: 9 additions & 11 deletions shared/elasticsearch/src/esClientUtils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const { logger } = require("@shared/utils");

const { analyzer, char_filter, filter, tokenizer } = require("./analysis");

async function createIndex({ client, indexName, mappings }) {
const body = await client.indices.exists({ index: indexName });
if (body) {
try {
await client.indices.delete({ index: indexName });
logger.info(`Index ${indexName} deleted.`);
console.info(`Index ${indexName} deleted.`);
} catch (error) {
logger.error("index delete", error);
console.error("index delete", error);
}
}
try {
Expand All @@ -31,15 +29,15 @@ async function createIndex({ client, indexName, mappings }) {
},
index: indexName,
});
logger.info(`Index ${indexName} created.`);
console.info(`Index ${indexName} created.`);
} catch (error) {
logger.error("index create", error);
console.error("index create", error);
}
}

async function version({ client }) {
const body = await client.info();
logger.info(body.version.number);
console.info(body.version.number);
}

async function bulkIndexDocuments({ client, indexName, documents }) {
Expand Down Expand Up @@ -67,9 +65,9 @@ async function bulkIndexDocuments({ client, indexName, documents }) {
const errorDocs = resp.items.filter((item) => item.index.status !== 201);
throw new Error(`Error during indexing ${JSON.stringify(errorDocs)}`);
}
logger.info(`Index ${documents.length} documents.`);
console.info(`Index ${documents.length} documents.`);
} catch (error) {
logger.error(`Failed to index documents (${error})`);
console.error(`Failed to index documents (${error})`);
throw error;
}
}
Expand All @@ -80,7 +78,7 @@ async function indexDocumentsBatched({
documents,
size = 500,
}) {
logger.info(`Loaded ${documents.length} documents`);
console.info(`Loaded ${documents.length} documents`);
for (const chunk of chunks(documents, size)) {
await bulkIndexDocuments({ client, documents: chunk, indexName });
}
Expand All @@ -95,7 +93,7 @@ async function deleteOldIndex({ client, patterns, timestamp }) {
);

return Promise.all(pIndicesToDelete).then(() => {
logger.info(
console.info(
`Remove ${pIndicesToDelete.length} old indices (${JSON.stringify(
IndicesToDelete
)})`
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5486,7 +5486,6 @@ __metadata:
"@babel/core": ^7.15.5
"@babel/plugin-transform-modules-commonjs": ^7.15.4
"@shared/eslint-config": "workspace:^"
"@shared/utils": "workspace:^"
got: ^11.8.2
jest: ^27.1.1
lint-staged: ^12.0.0
Expand Down

0 comments on commit 61c20c7

Please sign in to comment.