{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/kibana/pulls/comments/118784579","pull_request_review_id":40613706,"id":118784579,"diff_hunk":"@@ -0,0 +1,124 @@\n+import sinon from 'sinon';\n+import expect from 'expect.js';\n+\n+import { convertEsIndexNotFoundError } from '../errors';\n+import * as convertEsIndexNotFoundErrorNS from '../errors';\n+\n+import { callIndexAliasApi, callFieldCapsApi } from '../es_api';\n+\n+describe('server/index_patterns/service/lib/es_api', () => {\n+  describe('#callIndexAliasApi()', () => {\n+    let sandbox;\n+    beforeEach(() => sandbox = sinon.sandbox.create());\n+    afterEach(() => sandbox.restore());\n+\n+    it('calls indices.getAlias() via callCluster', async () => {\n+      const callCluster = sinon.stub();\n+      await callIndexAliasApi(callCluster);\n+      sinon.assert.calledOnce(callCluster);\n+      sinon.assert.calledWith(callCluster, 'indices.getAlias');\n+    });\n+\n+    it('passes indices directly to es api', async () => {\n+      const football = {};\n+      const callCluster = sinon.stub();\n+      await callIndexAliasApi(callCluster, football);\n+      sinon.assert.calledOnce(callCluster);\n+      expect(callCluster.args[0][1].index).to.be(football);\n+    });\n+\n+    it('returns the es response directly', async () => {\n+      const football = {};\n+      const callCluster = sinon.stub().returns(football);\n+      const resp = await callIndexAliasApi(callCluster);\n+      sinon.assert.calledOnce(callCluster);\n+      expect(resp).to.be(football);\n+    });\n+\n+    it('sets ignoreUnavailable and allowNoIndices params', async () => {\n+      const callCluster = sinon.stub();\n+      await callIndexAliasApi(callCluster);\n+      sinon.assert.calledOnce(callCluster);\n+\n+      const passedOpts = callCluster.args[0][1];\n+      expect(passedOpts).to.have.property('ignoreUnavailable', true);\n+      expect(passedOpts).to.have.property('allowNoIndices', false);\n+    });\n+\n+    it('handles errors with convertEsIndexNotFoundError()', async () => {\n+      const indices = [];\n+      const esError = new Error('esError');\n+      const convertedError = new Error('convertedError');\n+\n+      sandbox.stub(convertEsIndexNotFoundErrorNS, 'convertEsIndexNotFoundError', () => { throw convertedError; });\n+      const callCluster = sinon.spy(async () => { throw esError; });\n+      try {\n+        await callIndexAliasApi(callCluster, indices);\n+        throw new Error('expected callIndexAliasApi() to throw');\n+      } catch (error) {\n+        expect(error).to.be(convertedError);\n+        sinon.assert.calledOnce(convertEsIndexNotFoundError);\n+        expect(convertEsIndexNotFoundError.args[0][0]).to.be(indices);\n+        expect(convertEsIndexNotFoundError.args[0][1]).to.be(esError);\n+      }\n+    });\n+  });\n+\n+  describe('#callFieldCapsApi()', () => {\n+    let sandbox;\n+    beforeEach(() => sandbox = sinon.sandbox.create());","path":"src/server/index_patterns/service/lib/__tests__/es_api.js","position":69,"original_position":69,"commit_id":"f37b368a3dd88ae6bc0bc4671bf760e5c4b4c658","original_commit_id":"d99420ef238053490b4d7140e9510a32941ea814","user":{"login":"kjbekkelund","id":5259,"avatar_url":"https://avatars1.githubusercontent.com/u/5259?v=3","gravatar_id":"","url":"https://api.github.com/users/kjbekkelund","html_url":"https://github.com/kjbekkelund","followers_url":"https://api.github.com/users/kjbekkelund/followers","following_url":"https://api.github.com/users/kjbekkelund/following{/other_user}","gists_url":"https://api.github.com/users/kjbekkelund/gists{/gist_id}","starred_url":"https://api.github.com/users/kjbekkelund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjbekkelund/subscriptions","organizations_url":"https://api.github.com/users/kjbekkelund/orgs","repos_url":"https://api.github.com/users/kjbekkelund/repos","events_url":"https://api.github.com/users/kjbekkelund/events{/privacy}","received_events_url":"https://api.github.com/users/kjbekkelund/received_events","type":"User","site_admin":false},"body":"I ❤️ the move to `sandbox`","created_at":"2017-05-26T20:31:48Z","updated_at":"2017-05-26T20:58:36Z","html_url":"https://github.com/elastic/kibana/pull/11114#discussion_r118784579","pull_request_url":"https://api.github.com/repos/elastic/kibana/pulls/11114","_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments/118784579"},"html":{"href":"https://github.com/elastic/kibana/pull/11114#discussion_r118784579"},"pull_request":{"href":"https://api.github.com/repos/elastic/kibana/pulls/11114"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/kibana/pulls/11114","id":114922985,"html_url":"https://github.com/elastic/kibana/pull/11114","diff_url":"https://github.com/elastic/kibana/pull/11114.diff","patch_url":"https://github.com/elastic/kibana/pull/11114.patch","issue_url":"https://api.github.com/repos/elastic/kibana/issues/11114","number":11114,"state":"open","locked":false,"title":"[IndexPatterns] Support cross cluster search","user":{"login":"spalger","id":1329312,"avatar_url":"https://avatars2.githubusercontent.com/u/1329312?v=3","gravatar_id":"","url":"https://api.github.com/users/spalger","html_url":"https://github.com/spalger","followers_url":"https://api.github.com/users/spalger/followers","following_url":"https://api.github.com/users/spalger/following{/other_user}","gists_url":"https://api.github.com/users/spalger/gists{/gist_id}","starred_url":"https://api.github.com/users/spalger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spalger/subscriptions","organizations_url":"https://api.github.com/users/spalger/orgs","repos_url":"https://api.github.com/users/spalger/repos","events_url":"https://api.github.com/users/spalger/events{/privacy}","received_events_url":"https://api.github.com/users/spalger/received_events","type":"User","site_admin":false},"body":"Closes #11014\r\nFixes #9028\r\nFixes #8373\r\nFixes #9224 \r\nFixes #9386 \r\nFIxes #9028\r\n... there are probably others\r\n\r\nWhen using cross cluster search, we have to pull the field definitions for index patterns in a cross-cluster friendly way, meaning we have to move over to the new cross cluster compatible `_field_caps` api in elasticsearch instead of pulling `_field_stats` and merging them with mappings.\r\n\r\nSummary:\r\n- Field fetching now happens on the server:\r\n   - `GET /api/index_patterns/_fields_for_wildcard?pattern=logstash-*`\r\n     - fetches fields for the `logstash-*` wildcard pattern\r\n     - fields are normalized, include kibana specific types and properties like `readFromDocValues`\r\n     - fields are sorted alphabetically, ready to be stored on index pattern objects.\r\n     - `&meta_fields=[\"_index\",\"_type\"]`\r\n        - include a list of meta fields in the query string to add private (prefixed with an underscore) or unknown fields to the response.\r\n   - `GET /api/index_patterns/_fields_for_time_pattern?pattern=[logstash-]YYYY&look_back=10`\r\n     - will do the same thing, but for time patterns\r\n     - Just like in master, `[logstash-]YYYY` is converted into a wildcard and then matched against the output of the `_aliases` api\r\n     - the most recent indices (`look_back` determines how many) are then used with the `_field_caps` api\r\n     - dependency on the `_aliases` endpoint means that time patterns are not cross cluster search compatible\r\n- Including a `:` in your index pattern converts it into a \"cross cluster\" index pattern and disables the `expand wildcard` and `time pattern` index pattern \"modes\"\r\n- Everything else is pretty much the same!\r\n","created_at":"2017-04-08T00:32:54Z","updated_at":"2017-05-26T20:58:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"182ab7e895e96f75ef911cd9d04098eed4bcb690","assignee":null,"assignees":[],"requested_reviewers":[{"login":"epixa","id":53814,"avatar_url":"https://avatars3.githubusercontent.com/u/53814?v=3","gravatar_id":"","url":"https://api.github.com/users/epixa","html_url":"https://github.com/epixa","followers_url":"https://api.github.com/users/epixa/followers","following_url":"https://api.github.com/users/epixa/following{/other_user}","gists_url":"https://api.github.com/users/epixa/gists{/gist_id}","starred_url":"https://api.github.com/users/epixa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/epixa/subscriptions","organizations_url":"https://api.github.com/users/epixa/orgs","repos_url":"https://api.github.com/users/epixa/repos","events_url":"https://api.github.com/users/epixa/events{/privacy}","received_events_url":"https://api.github.com/users/epixa/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/kibana/pulls/11114/commits","review_comments_url":"https://api.github.com/repos/elastic/kibana/pulls/11114/comments","review_comment_url":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/kibana/issues/11114/comments","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/f37b368a3dd88ae6bc0bc4671bf760e5c4b4c658","head":{"label":"spalger:implement/field-capabilities-api","ref":"implement/field-capabilities-api","sha":"f37b368a3dd88ae6bc0bc4671bf760e5c4b4c658","user":{"login":"spalger","id":1329312,"avatar_url":"https://avatars2.githubusercontent.com/u/1329312?v=3","gravatar_id":"","url":"https://api.github.com/users/spalger","html_url":"https://github.com/spalger","followers_url":"https://api.github.com/users/spalger/followers","following_url":"https://api.github.com/users/spalger/following{/other_user}","gists_url":"https://api.github.com/users/spalger/gists{/gist_id}","starred_url":"https://api.github.com/users/spalger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spalger/subscriptions","organizations_url":"https://api.github.com/users/spalger/orgs","repos_url":"https://api.github.com/users/spalger/repos","events_url":"https://api.github.com/users/spalger/events{/privacy}","received_events_url":"https://api.github.com/users/spalger/received_events","type":"User","site_admin":false},"repo":{"id":12307386,"name":"kibana","full_name":"spalger/kibana","owner":{"login":"spalger","id":1329312,"avatar_url":"https://avatars2.githubusercontent.com/u/1329312?v=3","gravatar_id":"","url":"https://api.github.com/users/spalger","html_url":"https://github.com/spalger","followers_url":"https://api.github.com/users/spalger/followers","following_url":"https://api.github.com/users/spalger/following{/other_user}","gists_url":"https://api.github.com/users/spalger/gists{/gist_id}","starred_url":"https://api.github.com/users/spalger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spalger/subscriptions","organizations_url":"https://api.github.com/users/spalger/orgs","repos_url":"https://api.github.com/users/spalger/repos","events_url":"https://api.github.com/users/spalger/events{/privacy}","received_events_url":"https://api.github.com/users/spalger/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/spalger/kibana","description":"Kibana","fork":true,"url":"https://api.github.com/repos/spalger/kibana","forks_url":"https://api.github.com/repos/spalger/kibana/forks","keys_url":"https://api.github.com/repos/spalger/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spalger/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spalger/kibana/teams","hooks_url":"https://api.github.com/repos/spalger/kibana/hooks","issue_events_url":"https://api.github.com/repos/spalger/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/spalger/kibana/events","assignees_url":"https://api.github.com/repos/spalger/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/spalger/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/spalger/kibana/tags","blobs_url":"https://api.github.com/repos/spalger/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spalger/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spalger/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/spalger/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spalger/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/spalger/kibana/languages","stargazers_url":"https://api.github.com/repos/spalger/kibana/stargazers","contributors_url":"https://api.github.com/repos/spalger/kibana/contributors","subscribers_url":"https://api.github.com/repos/spalger/kibana/subscribers","subscription_url":"https://api.github.com/repos/spalger/kibana/subscription","commits_url":"https://api.github.com/repos/spalger/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/spalger/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/spalger/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/spalger/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/spalger/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/spalger/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spalger/kibana/merges","archive_url":"https://api.github.com/repos/spalger/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spalger/kibana/downloads","issues_url":"https://api.github.com/repos/spalger/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/spalger/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/spalger/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/spalger/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spalger/kibana/labels{/name}","releases_url":"https://api.github.com/repos/spalger/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/spalger/kibana/deployments","created_at":"2013-08-22T20:39:03Z","updated_at":"2016-11-10T01:38:25Z","pushed_at":"2017-05-26T20:51:01Z","git_url":"git://github.com/spalger/kibana.git","ssh_url":"git@github.com:spalger/kibana.git","clone_url":"https://github.com/spalger/kibana.git","svn_url":"https://github.com/spalger/kibana","homepage":"http://www.elasticsearch.org/overview/kibana/","size":298978,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"d4db4f5b48519ff61eb0359b2ad479711259c7af","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars3.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":7833168,"name":"kibana","full_name":"elastic/kibana","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars3.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/kibana","description":":bar_chart: Kibana analytics and search dashboard for Elasticsearch","fork":false,"url":"https://api.github.com/repos/elastic/kibana","forks_url":"https://api.github.com/repos/elastic/kibana/forks","keys_url":"https://api.github.com/repos/elastic/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/kibana/teams","hooks_url":"https://api.github.com/repos/elastic/kibana/hooks","issue_events_url":"https://api.github.com/repos/elastic/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/kibana/events","assignees_url":"https://api.github.com/repos/elastic/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/kibana/tags","blobs_url":"https://api.github.com/repos/elastic/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/kibana/languages","stargazers_url":"https://api.github.com/repos/elastic/kibana/stargazers","contributors_url":"https://api.github.com/repos/elastic/kibana/contributors","subscribers_url":"https://api.github.com/repos/elastic/kibana/subscribers","subscription_url":"https://api.github.com/repos/elastic/kibana/subscription","commits_url":"https://api.github.com/repos/elastic/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/kibana/merges","archive_url":"https://api.github.com/repos/elastic/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/kibana/downloads","issues_url":"https://api.github.com/repos/elastic/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/kibana/labels{/name}","releases_url":"https://api.github.com/repos/elastic/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/kibana/deployments","created_at":"2013-01-26T04:00:59Z","updated_at":"2017-05-26T15:03:36Z","pushed_at":"2017-05-26T20:51:03Z","git_url":"git://github.com/elastic/kibana.git","ssh_url":"git@github.com:elastic/kibana.git","clone_url":"https://github.com/elastic/kibana.git","svn_url":"https://github.com/elastic/kibana","homepage":"https://www.elastic.co/products/kibana","size":257170,"stargazers_count":7354,"watchers_count":7354,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2806,"mirror_url":null,"open_issues_count":1704,"forks":2806,"open_issues":1704,"watchers":7354,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/11114"},"html":{"href":"https://github.com/elastic/kibana/pull/11114"},"issue":{"href":"https://api.github.com/repos/elastic/kibana/issues/11114"},"comments":{"href":"https://api.github.com/repos/elastic/kibana/issues/11114/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/kibana/pulls/11114/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/kibana/pulls/11114/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/kibana/statuses/f37b368a3dd88ae6bc0bc4671bf760e5c4b4c658"}}}}
{"actor":{"display_login":"kjbekkelund"}}