async function readAndInsertBooks () {
try {
// Clear previous ES index
await esConnection.resetIndex()

// Read books directory
let files = fs.readdirSync('./books').filter(file => file.slice(-4) === '.txt')
console.log(`Found ${files.length} Files`)

// Read each book file, and index each paragraph in elasticsearch
for (let file of files) {
  console.log(`Reading File - ${file}`)
  const filePath = path.join('./books', file)
  const { title, author, paragraphs } = parseBookFile(filePath)
  await insertBookData(title, author, paragraphs)
}
} catch (err) {
console.error(err)
}
}
/** Clear ES index, parse and index all files from the books directory */
Clear ES index, parse and index all files from the books directory
Clear ES index parse and index all files from the books directory
async function readAndInsertBooks () {
try {
await esConnection.resetIndex()
let files = fs.readdirSync('./books').filter(file => file.slice(-4) === '.txt')
console.log(`Found ${files.length} Files`)
for (let file of files) {
  console.log(`Reading File - ${file}`)
  const filePath = path.join('./books', file)
  const { title, author, paragraphs } = parseBookFile(filePath)
  await insertBookData(title, author, paragraphs)
}
} catch (err) {
console.error(err)
}
}
async function readAndInsertBooks ( ) { try { await esConnection . resetIndex ( ) let files = fs . readdirSync ( './books' ) . filter ( file => file . slice ( - 4 ) === '.txt' ) console . log ( ` ${ files . length } ` ) for ( let file of files ) { console . log ( ` ${ file } ` ) const filePath = path . join ( './books' , file ) const { title , author , paragraphs } = parseBookFile ( filePath ) await insertBookData ( title , author , paragraphs ) } } catch ( err ) { console . error ( err ) } }
Clear ES index, parse and index all files from the books directory
Clear ES index parse and index all files from the books directory
// Clear previous ES index // Read books directory // Read each book file, and index each paragraph in elasticsearch