scrollgenerator

1.1.0 • Public • Published

Scroll Generator

is lite and quick set up package to scroll over elastic search index built using built in node js generator

How it work

all you have to do to scroll over an index is to give two params and done
- first import your elastic search client
example :
import client from "../libs/elasticsearch";
- import scrollOverIndex :
import scrollOverIndex from "scrollgenerator";
- write your optional options parameter
let options = {
  client: client,
  index: "my_index",
  sort: [
    {
      "my_field": {
        order: "asc",
      },
    },
  ],
  query: {
    match_all: {},
  },
  size: 500,
};
  • note : All of these options are required exepct size (default = 500)
  • finally write executable code with the imported scrollOverIndex function and scrollRun callback
async function main() {
  await scrollOverIndex(options, scrollRun);
  console.log("scrolling over index done :)");
}

main();
  • the scrollRun will run in evey batch of hits
  • example of scrollRun callback :
async function scrollRun(result) {
  for (let item of result.hits.hits) {
    console.log(`data length :|| ${result.hits.total.value}`);
    console.log(item);
  }
  return;
}

Package Sidebar

Install

npm i scrollgenerator

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

4.95 kB

Total Files

4

Last publish

Collaborators

  • saidaitdriss