{"action":"created","comment":{"url":"https://api.github.com/repos/edx/course-discovery/pulls/comments/101215425","pull_request_review_id":21935567,"id":101215425,"diff_hunk":"@@ -10,31 +10,44 @@\n \n class ElasticsearchUtils(object):\n     @classmethod\n-    def create_alias_and_index(cls, es, alias):\n+    def create_alias_and_index(cls, es_connection, alias):\n         logger.info('Making sure alias [%s] exists...', alias)\n \n-        if es.indices.exists_alias(name=alias):\n+        if es_connection.indices.exists_alias(name=alias):\n             # If the alias exists, and points to an open index, we are all set.\n             logger.info('...alias exists.')\n         else:\n-            # Create an index with a unique (timestamped) name\n-            timestamp = datetime.datetime.utcnow().strftime(\"%Y%m%d%H%M%S\")\n-            index = '{alias}_{timestamp}'.format(alias=alias, timestamp=timestamp)\n-            index_settings = settings.ELASTICSEARCH_INDEX_SETTINGS\n-            index_settings['settings']['analysis']['filter']['synonym']['synonyms'] = get_synonyms(es)\n-            es.indices.create(index=index, body=index_settings)\n-            logger.info('...index [%s] created.', index)\n-\n+            index = cls.create_index(es_connection=es_connection, alias=alias)\n             # Point the alias to the new index\n             body = {\n                 'actions': [\n                     {'remove': {'alias': alias, 'index': '*'}},\n                     {'add': {'alias': alias, 'index': index}},\n                 ]\n             }\n-            es.indices.update_aliases(body)\n+            es_connection.indices.update_aliases(body)\n             logger.info('...alias updated.')\n \n+    @classmethod\n+    def create_index(cls, es_connection, alias):\n+        \"\"\"\n+        Creates a new index whose name is prefixed with the specified value.\n+\n+        Args:\n+            es_connection (Elasticsearch): Elasticsearch connection - (ElasticsearchSearchBackend.conn)\n+            alias (str): Alias for the connection, used as prefix for the index name\n+\n+        Returns:\n+            index_name (str): Name of the new index.\n+        \"\"\"\n+        timestamp = datetime.datetime.utcnow().strftime(\"%Y%m%d%H%M%S\")","path":"course_discovery/apps/core/utils.py","position":45,"original_position":45,"commit_id":"a6d4d52692cde946c14d8f62ee952015b8cf0642","original_commit_id":"a6d4d52692cde946c14d8f62ee952015b8cf0642","user":{"login":"clintonb","id":910510,"avatar_url":"https://avatars.githubusercontent.com/u/910510?v=3","gravatar_id":"","url":"https://api.github.com/users/clintonb","html_url":"https://github.com/clintonb","followers_url":"https://api.github.com/users/clintonb/followers","following_url":"https://api.github.com/users/clintonb/following{/other_user}","gists_url":"https://api.github.com/users/clintonb/gists{/gist_id}","starred_url":"https://api.github.com/users/clintonb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintonb/subscriptions","organizations_url":"https://api.github.com/users/clintonb/orgs","repos_url":"https://api.github.com/users/clintonb/repos","events_url":"https://api.github.com/users/clintonb/events{/privacy}","received_events_url":"https://api.github.com/users/clintonb/received_events","type":"User","site_admin":false},"body":"Nit: single quotes","created_at":"2017-02-15T07:24:59Z","updated_at":"2017-02-15T07:52:20Z","html_url":"https://github.com/edx/course-discovery/pull/646#discussion_r101215425","pull_request_url":"https://api.github.com/repos/edx/course-discovery/pulls/646","_links":{"self":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/comments/101215425"},"html":{"href":"https://github.com/edx/course-discovery/pull/646#discussion_r101215425"},"pull_request":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/646"}}},"pull_request":{"url":"https://api.github.com/repos/edx/course-discovery/pulls/646","id":105556853,"html_url":"https://github.com/edx/course-discovery/pull/646","diff_url":"https://github.com/edx/course-discovery/pull/646.diff","patch_url":"https://github.com/edx/course-discovery/pull/646.patch","issue_url":"https://api.github.com/repos/edx/course-discovery/issues/646","number":646,"state":"open","locked":false,"title":"Create remove_unused_indexes management command","user":{"login":"mikedikan","id":1236705,"avatar_url":"https://avatars.githubusercontent.com/u/1236705?v=3","gravatar_id":"","url":"https://api.github.com/users/mikedikan","html_url":"https://github.com/mikedikan","followers_url":"https://api.github.com/users/mikedikan/followers","following_url":"https://api.github.com/users/mikedikan/following{/other_user}","gists_url":"https://api.github.com/users/mikedikan/gists{/gist_id}","starred_url":"https://api.github.com/users/mikedikan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikedikan/subscriptions","organizations_url":"https://api.github.com/users/mikedikan/orgs","repos_url":"https://api.github.com/users/mikedikan/repos","events_url":"https://api.github.com/users/mikedikan/events{/privacy}","received_events_url":"https://api.github.com/users/mikedikan/received_events","type":"User","site_admin":false},"body":"ECOM-7129\r\n\r\nCreating management command to remove older indexes automatically, to clean up dangling elasticsearch indexes.\r\n\r\n@edx/ecommerce for review","created_at":"2017-02-10T02:46:12Z","updated_at":"2017-02-15T07:52:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fc92c6708637b57dde2dc5618a81facd3e6aae50","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx/course-discovery/pulls/646/commits","review_comments_url":"https://api.github.com/repos/edx/course-discovery/pulls/646/comments","review_comment_url":"https://api.github.com/repos/edx/course-discovery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/course-discovery/issues/646/comments","statuses_url":"https://api.github.com/repos/edx/course-discovery/statuses/a6d4d52692cde946c14d8f62ee952015b8cf0642","head":{"label":"edx:mdikan/remove_indexes_manage_command","ref":"mdikan/remove_indexes_manage_command","sha":"a6d4d52692cde946c14d8f62ee952015b8cf0642","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":45866355,"name":"course-discovery","full_name":"edx/course-discovery","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/course-discovery","description":"edX Course Catalog Service","fork":false,"url":"https://api.github.com/repos/edx/course-discovery","forks_url":"https://api.github.com/repos/edx/course-discovery/forks","keys_url":"https://api.github.com/repos/edx/course-discovery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/course-discovery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/course-discovery/teams","hooks_url":"https://api.github.com/repos/edx/course-discovery/hooks","issue_events_url":"https://api.github.com/repos/edx/course-discovery/issues/events{/number}","events_url":"https://api.github.com/repos/edx/course-discovery/events","assignees_url":"https://api.github.com/repos/edx/course-discovery/assignees{/user}","branches_url":"https://api.github.com/repos/edx/course-discovery/branches{/branch}","tags_url":"https://api.github.com/repos/edx/course-discovery/tags","blobs_url":"https://api.github.com/repos/edx/course-discovery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/course-discovery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/course-discovery/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/course-discovery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/course-discovery/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/course-discovery/languages","stargazers_url":"https://api.github.com/repos/edx/course-discovery/stargazers","contributors_url":"https://api.github.com/repos/edx/course-discovery/contributors","subscribers_url":"https://api.github.com/repos/edx/course-discovery/subscribers","subscription_url":"https://api.github.com/repos/edx/course-discovery/subscription","commits_url":"https://api.github.com/repos/edx/course-discovery/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/course-discovery/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/course-discovery/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/course-discovery/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/course-discovery/contents/{+path}","compare_url":"https://api.github.com/repos/edx/course-discovery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/course-discovery/merges","archive_url":"https://api.github.com/repos/edx/course-discovery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/course-discovery/downloads","issues_url":"https://api.github.com/repos/edx/course-discovery/issues{/number}","pulls_url":"https://api.github.com/repos/edx/course-discovery/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/course-discovery/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/course-discovery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/course-discovery/labels{/name}","releases_url":"https://api.github.com/repos/edx/course-discovery/releases{/id}","deployments_url":"https://api.github.com/repos/edx/course-discovery/deployments","created_at":"2015-11-09T20:57:54Z","updated_at":"2017-01-30T22:01:27Z","pushed_at":"2017-02-15T07:34:09Z","git_url":"git://github.com/edx/course-discovery.git","ssh_url":"git@github.com:edx/course-discovery.git","clone_url":"https://github.com/edx/course-discovery.git","svn_url":"https://github.com/edx/course-discovery","homepage":"","size":4972,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":10,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"410c54d20e6e73f664656c1db5e2790ae5884266","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":45866355,"name":"course-discovery","full_name":"edx/course-discovery","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/course-discovery","description":"edX Course Catalog Service","fork":false,"url":"https://api.github.com/repos/edx/course-discovery","forks_url":"https://api.github.com/repos/edx/course-discovery/forks","keys_url":"https://api.github.com/repos/edx/course-discovery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/course-discovery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/course-discovery/teams","hooks_url":"https://api.github.com/repos/edx/course-discovery/hooks","issue_events_url":"https://api.github.com/repos/edx/course-discovery/issues/events{/number}","events_url":"https://api.github.com/repos/edx/course-discovery/events","assignees_url":"https://api.github.com/repos/edx/course-discovery/assignees{/user}","branches_url":"https://api.github.com/repos/edx/course-discovery/branches{/branch}","tags_url":"https://api.github.com/repos/edx/course-discovery/tags","blobs_url":"https://api.github.com/repos/edx/course-discovery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/course-discovery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/course-discovery/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/course-discovery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/course-discovery/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/course-discovery/languages","stargazers_url":"https://api.github.com/repos/edx/course-discovery/stargazers","contributors_url":"https://api.github.com/repos/edx/course-discovery/contributors","subscribers_url":"https://api.github.com/repos/edx/course-discovery/subscribers","subscription_url":"https://api.github.com/repos/edx/course-discovery/subscription","commits_url":"https://api.github.com/repos/edx/course-discovery/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/course-discovery/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/course-discovery/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/course-discovery/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/course-discovery/contents/{+path}","compare_url":"https://api.github.com/repos/edx/course-discovery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/course-discovery/merges","archive_url":"https://api.github.com/repos/edx/course-discovery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/course-discovery/downloads","issues_url":"https://api.github.com/repos/edx/course-discovery/issues{/number}","pulls_url":"https://api.github.com/repos/edx/course-discovery/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/course-discovery/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/course-discovery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/course-discovery/labels{/name}","releases_url":"https://api.github.com/repos/edx/course-discovery/releases{/id}","deployments_url":"https://api.github.com/repos/edx/course-discovery/deployments","created_at":"2015-11-09T20:57:54Z","updated_at":"2017-01-30T22:01:27Z","pushed_at":"2017-02-15T07:34:09Z","git_url":"git://github.com/edx/course-discovery.git","ssh_url":"git@github.com:edx/course-discovery.git","clone_url":"https://github.com/edx/course-discovery.git","svn_url":"https://github.com/edx/course-discovery","homepage":"","size":4972,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/646"},"html":{"href":"https://github.com/edx/course-discovery/pull/646"},"issue":{"href":"https://api.github.com/repos/edx/course-discovery/issues/646"},"comments":{"href":"https://api.github.com/repos/edx/course-discovery/issues/646/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/646/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/course-discovery/pulls/646/commits"},"statuses":{"href":"https://api.github.com/repos/edx/course-discovery/statuses/a6d4d52692cde946c14d8f62ee952015b8cf0642"}}}}
{"actor":{"display_login":"clintonb"}}