Skip to content

Conversation

@delvedor
Copy link
Member

@delvedor delvedor commented Apr 1, 2020

Now you can use an async generator as datasource in the bulk helper!

const { Client } = require('@elastic/elasticsearch')

async function * generator () {
  const dataset = [
    { user: 'jon', age: 23 },
    { user: 'arya', age: 18 },
    { user: 'tyrion', age: 39 }
  ]
  for (const doc of dataset) {
    yield doc
  }
}

const client = new Client({ node: 'http://localhost:9200' })
const result = await client.helpers.bulk({
  datasource: generator(),
  onDocument (doc) {
    return {
      index: { _index: 'my-index' }
    }
  }
})

console.log(result)

@delvedor delvedor merged commit df17fb9 into master Apr 3, 2020
@delvedor delvedor deleted the async-generator-support branch April 3, 2020 07:46
@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 2020

The backport to 7.x failed:

The process 'git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-7.x 7.x
# Navigate to the new working tree
cd .worktrees/backport-7.x
# Create a new branch
git switch --create backport-1138-to-7.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick df17fb99d06b15042f235b115ee8d0f1d0225c30
# Push it to GitHub
git push --set-upstream origin backport-1138-to-7.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-7.x

Then, create a pull request where the base branch is 7.x and the compare/head branch is backport-1138-to-7.x.

delvedor added a commit that referenced this pull request Apr 3, 2020
* Added async generator support in bulk helper

* Updated test

* Updated docs

* Improved type definitions

* Updated onDrop callback type definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants