{"id":4750,"date":"2016-07-23T23:45:36","date_gmt":"2016-07-23T23:45:36","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4750"},"modified":"2016-07-23T23:45:36","modified_gmt":"2016-07-23T23:45:36","slug":"importing-openlibrary-data-rethinkdb","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/","title":{"rendered":"Importing OpenLibrary data into RethinkDB"},"content":{"rendered":"<p>You can download lists of books and authors from the Open Library<sup><a href=\"#footnote_1_4750\" id=\"identifier_1_4750\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/openlibrary.org\/developers\/dumps\">1<\/a><\/sup>. The data dumps are formatted simply, as a tab separated file, with the last column being JSON data.<\/p>\n<pre>\ntype - type of record (\/type\/edition, \/type\/work etc.)\nkey - unique key of the record. (\/books\/OL1M etc.)\nrevision - revision number of the record\nlast_modified - last modified timestamp\nJSON - the complete record in JSON format\n<\/pre>\n<p>To do this, you need to split the line, and parse the JSON data. <\/p>\n<pre lang=\"javascript\">\nimport * as r from 'rethinkdb';\n\nfunction parseLine(line: string) {\n  const columns = line.split(\"\\t\");\n  return {\n    type: columns[0],\n    data: columns[4]\n  }\n}\n\nfunction onError(err, result) {\n  if (err) throw err;\n}\n\nfunction run() {\n  const fs = require('fs'),\n        byline = require('byline');\n\n  r.connect( {host: 'localhost', port: 28015}, \n    function(err, conn) {\n      if (err) throw err;\n\n      const stream = byline(\n        fs.createReadStream('works.txt', { encoding: 'utf8' })\n      );\n      var options = {};\n\n      options['durability'] = 'soft';\n      options['returnChanges'] = false;\n\n      var lines = [];\n      function onRowComplete(line) {\n        r.db('openlibrary').table('works').insert(\n          JSON.parse(parseLine(line).data),\n          options\n        ).run(conn, onError)\n\n        lines = [];\n      }\n\n      stream.on('data', onRowComplete);\n    })\n}\n<\/pre>\n<p>The data files are quite large, so you need to be careful about memory allocation &#8211; make sure to not allocate too many objects in the process. The options set on the import make it run much faster.<\/p>\n<p>When you run it, you&#8217;ll also need to use memory settings for Node:<\/p>\n<pre lang=\"bash\">\nnode --max_old_space_size=2000000 dist\/run.js\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_1_4750\" class=\"footnote\">https:\/\/openlibrary.org\/developers\/dumps<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_1_4750\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Importing Open Library data into RethinkDB<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[12],"tags":[403,466],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Importing Open Library data into RethinkDB\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"gary\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Gary Sieling - Software Engineer\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Importing OpenLibrary data into RethinkDB - Gary Sieling\" \/>\n\t\t<meta property=\"og:description\" content=\"Importing Open Library data into RethinkDB\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2016-07-23T23:45:36+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2016-07-23T23:45:36+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Importing OpenLibrary data into RethinkDB - Gary Sieling\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Importing Open Library data into RethinkDB\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#blogposting\",\"name\":\"Importing OpenLibrary data into RethinkDB - Gary Sieling\",\"headline\":\"Importing OpenLibrary data into RethinkDB\",\"author\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\"},\"datePublished\":\"2016-07-23T23:45:36+00:00\",\"dateModified\":\"2016-07-23T23:45:36+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#webpage\"},\"articleSection\":\"How-To, open library, rethinkdb\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.garysieling.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/how-to\\\/#listItem\",\"name\":\"How-To\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/how-to\\\/#listItem\",\"position\":2,\"name\":\"How-To\",\"item\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/how-to\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#listItem\",\"name\":\"Importing OpenLibrary data into RethinkDB\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#listItem\",\"position\":3,\"name\":\"Importing OpenLibrary data into RethinkDB\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/category\\\/how-to\\\/#listItem\",\"name\":\"How-To\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\",\"name\":\"Gary Sieling\",\"description\":\"Software Engineer\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/\",\"name\":\"gary\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0be925276d848ffe98a6a9dc8cf33e67?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"gary\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#webpage\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/\",\"name\":\"Importing OpenLibrary data into RethinkDB - Gary Sieling\",\"description\":\"Importing Open Library data into RethinkDB\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/importing-openlibrary-data-rethinkdb\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/author\\\/gary\\\/#author\"},\"datePublished\":\"2016-07-23T23:45:36+00:00\",\"dateModified\":\"2016-07-23T23:45:36+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/\",\"name\":\"Gary Sieling\",\"description\":\"Software Engineer\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.garysieling.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Importing OpenLibrary data into RethinkDB - Gary Sieling","description":"Importing Open Library data into RethinkDB","canonical_url":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#blogposting","name":"Importing OpenLibrary data into RethinkDB - Gary Sieling","headline":"Importing OpenLibrary data into RethinkDB","author":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"publisher":{"@id":"https:\/\/www.garysieling.com\/blog\/#organization"},"datePublished":"2016-07-23T23:45:36+00:00","dateModified":"2016-07-23T23:45:36+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#webpage"},"isPartOf":{"@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#webpage"},"articleSection":"How-To, open library, rethinkdb"},{"@type":"BreadcrumbList","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.garysieling.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/how-to\/#listItem","name":"How-To"}},{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/how-to\/#listItem","position":2,"name":"How-To","item":"https:\/\/www.garysieling.com\/blog\/category\/how-to\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#listItem","name":"Importing OpenLibrary data into RethinkDB"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#listItem","position":3,"name":"Importing OpenLibrary data into RethinkDB","previousItem":{"@type":"ListItem","@id":"https:\/\/www.garysieling.com\/blog\/category\/how-to\/#listItem","name":"How-To"}}]},{"@type":"Organization","@id":"https:\/\/www.garysieling.com\/blog\/#organization","name":"Gary Sieling","description":"Software Engineer","url":"https:\/\/www.garysieling.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author","url":"https:\/\/www.garysieling.com\/blog\/author\/gary\/","name":"gary","image":{"@type":"ImageObject","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/0be925276d848ffe98a6a9dc8cf33e67?s=96&d=identicon&r=g","width":96,"height":96,"caption":"gary"}},{"@type":"WebPage","@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#webpage","url":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/","name":"Importing OpenLibrary data into RethinkDB - Gary Sieling","description":"Importing Open Library data into RethinkDB","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.garysieling.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/#breadcrumblist"},"author":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"creator":{"@id":"https:\/\/www.garysieling.com\/blog\/author\/gary\/#author"},"datePublished":"2016-07-23T23:45:36+00:00","dateModified":"2016-07-23T23:45:36+00:00"},{"@type":"WebSite","@id":"https:\/\/www.garysieling.com\/blog\/#website","url":"https:\/\/www.garysieling.com\/blog\/","name":"Gary Sieling","description":"Software Engineer","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.garysieling.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Gary Sieling - Software Engineer","og:type":"article","og:title":"Importing OpenLibrary data into RethinkDB - Gary Sieling","og:description":"Importing Open Library data into RethinkDB","og:url":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/","article:published_time":"2016-07-23T23:45:36+00:00","article:modified_time":"2016-07-23T23:45:36+00:00","twitter:card":"summary_large_image","twitter:title":"Importing OpenLibrary data into RethinkDB - Gary Sieling","twitter:description":"Importing Open Library data into RethinkDB"},"aioseo_meta_data":{"post_id":"4750","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2023-02-04 17:02:39","updated":"2026-07-06 02:09:48","ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.garysieling.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.garysieling.com\/blog\/category\/how-to\/\" title=\"How-To\">How-To<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tImporting OpenLibrary data into RethinkDB\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.garysieling.com\/blog"},{"label":"How-To","link":"https:\/\/www.garysieling.com\/blog\/category\/how-to\/"},{"label":"Importing OpenLibrary data into RethinkDB","link":"https:\/\/www.garysieling.com\/blog\/importing-openlibrary-data-rethinkdb\/"}],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4750"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4750"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4750\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}