Skip to content

Said-Ait-Driss/scrollGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
}

About

scrollGenerator is lite and quick set up package to scroll over elastic search index

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published