{"action":"created","comment":{"url":"https://api.github.com/repos/nymag/amphora/pulls/comments/86209400","pull_request_review_id":6878829,"id":86209400,"diff_hunk":"@@ -0,0 +1,404 @@\n+'use strict';\n+\n+const elastic = require('elasticsearch'),\n+  bluebird = require('bluebird'),\n+  _ = require('lodash'),\n+  util = require('util'),\n+  log = require('./log').withStandardPrefix(__filename),\n+  endpoint = process.env.ELASTIC_HOST || '',\n+  serverConfig = {\n+    host: endpoint,\n+    maxSockets: 500,\n+    apiVersion: '1.7',\n+    // log: ['error', 'trace'],\n+    defer: require('../utils/defer')\n+  };\n+\n+var client,\n+  aliasSuffix = '';\n+\n+/**\n+ * Test whether or not the client is connected\n+ * to Elastic\n+ *\n+ * @param  {object} currentClient\n+ * @returns {Promise}\n+ */\n+function healthCheck(currentClient) {\n+  return currentClient.ping({\n+    requestTimeout: 1000\n+  }).then(function () {\n+    log('info', 'Elasticsearch cluster is up!');\n+    return bluebird.resolve();\n+  }).catch(function (error) {\n+    log('info', 'Elasticsearch cluster is down!');\n+    return bluebird.reject(error);\n+  });\n+}\n+\n+/**\n+ * Create an Elasticsearch index\n+ *\n+ * @param {string} index\n+ * @param {object} mappings\n+ * @returns {Promise}\n+ */\n+function initIndex(index, mappings) {\n+  return client.indices.create({\n+    index: index,\n+    body: mappings\n+  }).then(function () {\n+    log('info', 'Successfully created ' + index);\n+  })\n+    .catch(function (error) {\n+      log('error', error);\n+      return bluebird.reject(error);\n+    });\n+}\n+\n+/**\n+ * Check if an Elasticsearch index exists\n+ *\n+ * @param {string} index\n+ * @returns {Promise}\n+ */\n+function existsIndex(index) {\n+  return client.indices.exists({\n+    index: index\n+  });\n+}\n+\n+/**\n+ * Indices should have a different name than the alias\n+ * Append the `aliasSuffix` to newly created indices\n+ *\n+ * @param {string} alias\n+ * @returns {string}\n+ */\n+function createIndexName(alias) {\n+  return alias + aliasSuffix;\n+}\n+\n+/**\n+ * Delete an Elasticsearch index\n+ *\n+ * @param {string} index\n+ * @returns {Promise}\n+ */\n+function delIndex(index) {\n+  return client.indices.delete({\n+    index: index\n+  }).then(function () {\n+    log('info', 'Successfully deleted ' + index);\n+  })\n+    .catch(function (error) {\n+      log('error', error);\n+      return bluebird.reject(error);\n+    });\n+}","path":"lib/services/search.js","position":57,"original_position":98,"commit_id":"6d629e2d3649694f6d03491b07c695ae6e5f278b","original_commit_id":"6d629e2d3649694f6d03491b07c695ae6e5f278b","user":{"login":"larrychevres","id":1577777,"avatar_url":"https://avatars.githubusercontent.com/u/1577777?v=3","gravatar_id":"","url":"https://api.github.com/users/larrychevres","html_url":"https://github.com/larrychevres","followers_url":"https://api.github.com/users/larrychevres/followers","following_url":"https://api.github.com/users/larrychevres/following{/other_user}","gists_url":"https://api.github.com/users/larrychevres/gists{/gist_id}","starred_url":"https://api.github.com/users/larrychevres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larrychevres/subscriptions","organizations_url":"https://api.github.com/users/larrychevres/orgs","repos_url":"https://api.github.com/users/larrychevres/repos","events_url":"https://api.github.com/users/larrychevres/events{/privacy}","received_events_url":"https://api.github.com/users/larrychevres/received_events","type":"User","site_admin":false},"body":"In general we don't delete indexes, or at the very least, we leave that to Ops. Do we need to have that? What's the use case. The whole alias/index relationship is to enable rollback, so when would you delete?","created_at":"2016-11-02T18:19:27Z","updated_at":"2016-11-02T18:19:27Z","html_url":"https://github.com/nymag/amphora/pull/327#discussion_r86209400","pull_request_url":"https://api.github.com/repos/nymag/amphora/pulls/327","_links":{"self":{"href":"https://api.github.com/repos/nymag/amphora/pulls/comments/86209400"},"html":{"href":"https://github.com/nymag/amphora/pull/327#discussion_r86209400"},"pull_request":{"href":"https://api.github.com/repos/nymag/amphora/pulls/327"}}},"pull_request":{"url":"https://api.github.com/repos/nymag/amphora/pulls/327","id":91843157,"html_url":"https://github.com/nymag/amphora/pull/327","diff_url":"https://github.com/nymag/amphora/pull/327.diff","patch_url":"https://github.com/nymag/amphora/pull/327.patch","issue_url":"https://api.github.com/repos/nymag/amphora/issues/327","number":327,"state":"open","locked":false,"title":"Elastic Integration","user":{"login":"jonwinton","id":4906712,"avatar_url":"https://avatars.githubusercontent.com/u/4906712?v=3","gravatar_id":"","url":"https://api.github.com/users/jonwinton","html_url":"https://github.com/jonwinton","followers_url":"https://api.github.com/users/jonwinton/followers","following_url":"https://api.github.com/users/jonwinton/following{/other_user}","gists_url":"https://api.github.com/users/jonwinton/gists{/gist_id}","starred_url":"https://api.github.com/users/jonwinton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonwinton/subscriptions","organizations_url":"https://api.github.com/users/jonwinton/orgs","repos_url":"https://api.github.com/users/jonwinton/repos","events_url":"https://api.github.com/users/jonwinton/events{/privacy}","received_events_url":"https://api.github.com/users/jonwinton/received_events","type":"User","site_admin":false},"body":" Creates a search service in Amphora which can be used to index content. Implementation can be found here: https://github.com/nymag/sites/compare/search-service?expand=1","created_at":"2016-11-01T19:00:53Z","updated_at":"2016-11-02T18:19:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6f29bedf1a239fbdddc61ab9aafd605fac83def2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nymag/amphora/pulls/327/commits","review_comments_url":"https://api.github.com/repos/nymag/amphora/pulls/327/comments","review_comment_url":"https://api.github.com/repos/nymag/amphora/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nymag/amphora/issues/327/comments","statuses_url":"https://api.github.com/repos/nymag/amphora/statuses/6d629e2d3649694f6d03491b07c695ae6e5f278b","head":{"label":"nymag:search-service","ref":"search-service","sha":"6d629e2d3649694f6d03491b07c695ae6e5f278b","user":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"repo":{"id":32480128,"name":"amphora","full_name":"nymag/amphora","owner":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nymag/amphora","description":"Middleware for Express that composes components into renderable pages","fork":false,"url":"https://api.github.com/repos/nymag/amphora","forks_url":"https://api.github.com/repos/nymag/amphora/forks","keys_url":"https://api.github.com/repos/nymag/amphora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nymag/amphora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nymag/amphora/teams","hooks_url":"https://api.github.com/repos/nymag/amphora/hooks","issue_events_url":"https://api.github.com/repos/nymag/amphora/issues/events{/number}","events_url":"https://api.github.com/repos/nymag/amphora/events","assignees_url":"https://api.github.com/repos/nymag/amphora/assignees{/user}","branches_url":"https://api.github.com/repos/nymag/amphora/branches{/branch}","tags_url":"https://api.github.com/repos/nymag/amphora/tags","blobs_url":"https://api.github.com/repos/nymag/amphora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nymag/amphora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nymag/amphora/git/refs{/sha}","trees_url":"https://api.github.com/repos/nymag/amphora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nymag/amphora/statuses/{sha}","languages_url":"https://api.github.com/repos/nymag/amphora/languages","stargazers_url":"https://api.github.com/repos/nymag/amphora/stargazers","contributors_url":"https://api.github.com/repos/nymag/amphora/contributors","subscribers_url":"https://api.github.com/repos/nymag/amphora/subscribers","subscription_url":"https://api.github.com/repos/nymag/amphora/subscription","commits_url":"https://api.github.com/repos/nymag/amphora/commits{/sha}","git_commits_url":"https://api.github.com/repos/nymag/amphora/git/commits{/sha}","comments_url":"https://api.github.com/repos/nymag/amphora/comments{/number}","issue_comment_url":"https://api.github.com/repos/nymag/amphora/issues/comments{/number}","contents_url":"https://api.github.com/repos/nymag/amphora/contents/{+path}","compare_url":"https://api.github.com/repos/nymag/amphora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nymag/amphora/merges","archive_url":"https://api.github.com/repos/nymag/amphora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nymag/amphora/downloads","issues_url":"https://api.github.com/repos/nymag/amphora/issues{/number}","pulls_url":"https://api.github.com/repos/nymag/amphora/pulls{/number}","milestones_url":"https://api.github.com/repos/nymag/amphora/milestones{/number}","notifications_url":"https://api.github.com/repos/nymag/amphora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nymag/amphora/labels{/name}","releases_url":"https://api.github.com/repos/nymag/amphora/releases{/id}","deployments_url":"https://api.github.com/repos/nymag/amphora/deployments","created_at":"2015-03-18T19:38:22Z","updated_at":"2016-11-02T16:01:17Z","pushed_at":"2016-11-02T17:56:04Z","git_url":"git://github.com/nymag/amphora.git","ssh_url":"git@github.com:nymag/amphora.git","clone_url":"https://github.com/nymag/amphora.git","svn_url":"https://github.com/nymag/amphora","homepage":"","size":1060,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":11,"forks":3,"open_issues":11,"watchers":4,"default_branch":"master"}},"base":{"label":"nymag:master","ref":"master","sha":"0e2dc97bc03415c0b769a1586f43d38950c098da","user":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"repo":{"id":32480128,"name":"amphora","full_name":"nymag/amphora","owner":{"login":"nymag","id":1136688,"avatar_url":"https://avatars.githubusercontent.com/u/1136688?v=3","gravatar_id":"","url":"https://api.github.com/users/nymag","html_url":"https://github.com/nymag","followers_url":"https://api.github.com/users/nymag/followers","following_url":"https://api.github.com/users/nymag/following{/other_user}","gists_url":"https://api.github.com/users/nymag/gists{/gist_id}","starred_url":"https://api.github.com/users/nymag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nymag/subscriptions","organizations_url":"https://api.github.com/users/nymag/orgs","repos_url":"https://api.github.com/users/nymag/repos","events_url":"https://api.github.com/users/nymag/events{/privacy}","received_events_url":"https://api.github.com/users/nymag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nymag/amphora","description":"Middleware for Express that composes components into renderable pages","fork":false,"url":"https://api.github.com/repos/nymag/amphora","forks_url":"https://api.github.com/repos/nymag/amphora/forks","keys_url":"https://api.github.com/repos/nymag/amphora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nymag/amphora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nymag/amphora/teams","hooks_url":"https://api.github.com/repos/nymag/amphora/hooks","issue_events_url":"https://api.github.com/repos/nymag/amphora/issues/events{/number}","events_url":"https://api.github.com/repos/nymag/amphora/events","assignees_url":"https://api.github.com/repos/nymag/amphora/assignees{/user}","branches_url":"https://api.github.com/repos/nymag/amphora/branches{/branch}","tags_url":"https://api.github.com/repos/nymag/amphora/tags","blobs_url":"https://api.github.com/repos/nymag/amphora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nymag/amphora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nymag/amphora/git/refs{/sha}","trees_url":"https://api.github.com/repos/nymag/amphora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nymag/amphora/statuses/{sha}","languages_url":"https://api.github.com/repos/nymag/amphora/languages","stargazers_url":"https://api.github.com/repos/nymag/amphora/stargazers","contributors_url":"https://api.github.com/repos/nymag/amphora/contributors","subscribers_url":"https://api.github.com/repos/nymag/amphora/subscribers","subscription_url":"https://api.github.com/repos/nymag/amphora/subscription","commits_url":"https://api.github.com/repos/nymag/amphora/commits{/sha}","git_commits_url":"https://api.github.com/repos/nymag/amphora/git/commits{/sha}","comments_url":"https://api.github.com/repos/nymag/amphora/comments{/number}","issue_comment_url":"https://api.github.com/repos/nymag/amphora/issues/comments{/number}","contents_url":"https://api.github.com/repos/nymag/amphora/contents/{+path}","compare_url":"https://api.github.com/repos/nymag/amphora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nymag/amphora/merges","archive_url":"https://api.github.com/repos/nymag/amphora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nymag/amphora/downloads","issues_url":"https://api.github.com/repos/nymag/amphora/issues{/number}","pulls_url":"https://api.github.com/repos/nymag/amphora/pulls{/number}","milestones_url":"https://api.github.com/repos/nymag/amphora/milestones{/number}","notifications_url":"https://api.github.com/repos/nymag/amphora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nymag/amphora/labels{/name}","releases_url":"https://api.github.com/repos/nymag/amphora/releases{/id}","deployments_url":"https://api.github.com/repos/nymag/amphora/deployments","created_at":"2015-03-18T19:38:22Z","updated_at":"2016-11-02T16:01:17Z","pushed_at":"2016-11-02T17:56:04Z","git_url":"git://github.com/nymag/amphora.git","ssh_url":"git@github.com:nymag/amphora.git","clone_url":"https://github.com/nymag/amphora.git","svn_url":"https://github.com/nymag/amphora","homepage":"","size":1060,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":11,"forks":3,"open_issues":11,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nymag/amphora/pulls/327"},"html":{"href":"https://github.com/nymag/amphora/pull/327"},"issue":{"href":"https://api.github.com/repos/nymag/amphora/issues/327"},"comments":{"href":"https://api.github.com/repos/nymag/amphora/issues/327/comments"},"review_comments":{"href":"https://api.github.com/repos/nymag/amphora/pulls/327/comments"},"review_comment":{"href":"https://api.github.com/repos/nymag/amphora/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nymag/amphora/pulls/327/commits"},"statuses":{"href":"https://api.github.com/repos/nymag/amphora/statuses/6d629e2d3649694f6d03491b07c695ae6e5f278b"}}}}
{"actor":{"display_login":"larrychevres"}}