#community-help

Resolving Typesense Document Import Error

TLDR David struggled with accessing error.importResults from a failed document import with Typesense. After advice from Jason, the issue was resolved by logging each unsuccessful document through a for loop.

Powered by Struct AI
thinking_face1
6
11mo
Solved
Join the chat
Oct 22, 2022 (11 months ago)
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
07:45 AM
I get this error msg
[Typesense] Could not create document: ImportError: 913 documents imported successfully, 9 documents failed during import. Use `error.importResults` from the raised exception to get a detailed error reason for each document.

I'm struggling how see the error.importResults (i.e. I'm doing it wrong haha).

I'm doing something like this and none of the console logs in the catch prints what I'm after so I can debug and fix the documents that fail to import
try {
    const res = await typesenseClient
      .collections(collection)
      .documents()
      .import(searchIndex, { action: 'upsert' });
  } catch (error) {
    console.log(error);
    console.log(error.importResults.filter((r) => r.success === false));
    error.importResults
      .filter((r) => r.success === false)
      .forEach((r) => {
        console.log(r);
      });
}
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:52 PM
Could you console.log just error.importResults?
04:52
Jason
04:52 PM
Instead of filtering it?
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
04:54 PM
I hope I'm not that stupid that I never tried that. Not by my computer now but will report back my level of stupidity later
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:56 PM
Haha, I was just curious what the exact server output was. My current suspicion is that true / false might be returned as strings instead of booleans which is why the filter might not be working as expected…
Oct 24, 2022 (11 months ago)
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
11:04 AM
doing this worked 🤷
} catch (error) {
  for (let i = 0; i < error.importResults.length; i++) {
    if (error.importResults[i].success === false) {
      console.log(`Error With Document: ${error.importResults[i].error}`);
    }
  }
}
thinking_face1