diff --git a/cli.ts b/cli.ts index 22ce5a0..f5b4bf7 100644 --- a/cli.ts +++ b/cli.ts @@ -1,7 +1,7 @@ import { expandGlob } from 'std/fs/mod.ts'; import { config } from "std/dotenv/mod.ts"; import { chunk } from "https://deno.land/std/collections/chunk.ts" -import { Client as ElasticsearchClient } from "https://deno.land/x/elasticsearch@v8.3.3/mod.ts"; +import { Client as ElasticsearchClient, DocumentsBulkRequest } from "https://deno.land/x/elasticsearch@v8.3.3/mod.ts"; import { Doc, DocParser, readDoc } from './doc_load/load.ts'; import ProgressBar from 'https://deno.land/x/progress@v1.3.0/mod.ts'; import { Command } from "cliffy"; @@ -82,19 +82,30 @@ async function bulkIndex(path: string[],{ } return [ { - create: { + index: { _id: doc.author+"/"+doc.name, } }, doc - ] as [{ create: { _id: string } }, Doc]; + ] as [{ index: { _id: string } }, Doc]; } )); - const _ = await client.documents.bulk({ + const res = await client.documents.bulk({ target: 'github-awesome', body: docs.flat(), - }); - + } as DocumentsBulkRequest) as { + errors: boolean, + took: number, + items: unknown[] + }; + if (res.errors){ + if (progressBar){ + bar.console("error occurs!") + } + else { + console.log("error occurs!") + } + } if (progressBar) { bar.render(++i); }