Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch indexing #21

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { pathToFileURL } from 'url'
import { Client } from '@opensearch-project/opensearch'
import type { ClientOptions } from '@opensearch-project/opensearch'
import { exists } from './paths'
import chunk from 'lodash/chunk'

const jsonFilename = 'sandbox-search.json'
const jsFilename = 'sandbox-search.js'

async function getData(path: string) {
async function getData(path: string): Promise<object[]> {
let result
const jsonPath = join(path, jsonFilename)
const jsPath = join(path, jsFilename)
Expand Down Expand Up @@ -44,6 +45,10 @@ export async function populate(path: string, opts: ClientOptions) {
const data = await getData(path)
if (data) {
const client = new Client(opts)
await client.bulk({ body: data })
const batch_size = 10
lpsinger marked this conversation as resolved.
Show resolved Hide resolved
const batches = chunk(data, batch_size)
for (const batch of batches) {
await client.bulk({ body: batch })
}
}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@opensearch-project/opensearch": "^2.2.0",
"env-paths": "^3.0.0",
"lodash": "^4.17.21",
"make-fetch-happen": "^11.0.3",
"rimraf": "^4.1.2",
"tar": "^6.1.13",
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"@nasa-gcn/eslint-config-gitignore": "^0.0.1",
"@tsconfig/node14": "^1.0.3",
"@types/lodash": "^4.14.202",
"@types/make-fetch-happen": "^10.0.1",
"@types/node": "^18.13.0",
"@types/tar": "^6.1.4",
Expand Down