{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/kibana/issues/3494","labels_url":"https://api.github.com/repos/elastic/kibana/issues/3494/labels{/name}","comments_url":"https://api.github.com/repos/elastic/kibana/issues/3494/comments","events_url":"https://api.github.com/repos/elastic/kibana/issues/3494/events","html_url":"https://github.com/elastic/kibana/issues/3494","id":65581304,"number":3494,"title":"Unique count wrong when table includes terms query sub-aggregation ","user":{"login":"striglia","id":262630,"avatar_url":"https://avatars.githubusercontent.com/u/262630?v=3","gravatar_id":"","url":"https://api.github.com/users/striglia","html_url":"https://github.com/striglia","followers_url":"https://api.github.com/users/striglia/followers","following_url":"https://api.github.com/users/striglia/following{/other_user}","gists_url":"https://api.github.com/users/striglia/gists{/gist_id}","starred_url":"https://api.github.com/users/striglia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/striglia/subscriptions","organizations_url":"https://api.github.com/users/striglia/orgs","repos_url":"https://api.github.com/users/striglia/repos","events_url":"https://api.github.com/users/striglia/events{/privacy}","received_events_url":"https://api.github.com/users/striglia/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/kibana/labels/needs%20details","name":"needs details","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-01T01:29:41Z","updated_at":"2015-04-03T18:43:50Z","closed_at":null,"body":"Running Kibana 4.0.1. I create a Data Table (for readability) on a search and add two aggregations, one Count and one Unique Count on a particular field. Just doing this looks sane and normal:\r\n\r\n![normal_unique_count](https://cloud.githubusercontent.com/assets/262630/6932673/c330513a-d7d1-11e4-993f-be14141fdc23.png)\r\n\r\nNow I add a sub-aggregation using the terms option. On some (not all!) values in the terms there are unique counts higher than the non-unique counts: \r\n\r\n![broken_unique_count](https://cloud.githubusercontent.com/assets/262630/6932861/5be0c05c-d7d4-11e4-9033-ecaebfc44445.png)\r\n\r\nSmells related to #3314? In my example are the unique counts of the `business_id` field getting mis-correlated with the proper `partner_id` field from the terms sub-aggregation? I tried reproducing with other sub-aggregations without any luck. I can also reproduce using different keys for the terms query. In fact the exact same miscounting occurs even for fields with only a single value (in this case all documents have `active:True`):\r\n\r\n![alternate_broken_terms_subagg](https://cloud.githubusercontent.com/assets/262630/6932727/6a19747c-d7d2-11e4-8918-2ae526b5cc73.png)\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/kibana/issues/comments/89387010","html_url":"https://github.com/elastic/kibana/issues/3494#issuecomment-89387010","issue_url":"https://api.github.com/repos/elastic/kibana/issues/3494","id":89387010,"user":{"login":"rashidkpc","id":1250387,"avatar_url":"https://avatars.githubusercontent.com/u/1250387?v=3","gravatar_id":"","url":"https://api.github.com/users/rashidkpc","html_url":"https://github.com/rashidkpc","followers_url":"https://api.github.com/users/rashidkpc/followers","following_url":"https://api.github.com/users/rashidkpc/following{/other_user}","gists_url":"https://api.github.com/users/rashidkpc/gists{/gist_id}","starred_url":"https://api.github.com/users/rashidkpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashidkpc/subscriptions","organizations_url":"https://api.github.com/users/rashidkpc/orgs","repos_url":"https://api.github.com/users/rashidkpc/repos","events_url":"https://api.github.com/users/rashidkpc/events{/privacy}","received_events_url":"https://api.github.com/users/rashidkpc/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T18:43:50Z","updated_at":"2015-04-03T18:43:50Z","body":"I guess I'm not seeing what is incorrect from a Kibana standpoint? Do you feel the result of the aggregation is incorrect? If so you might talk to the Elasticsearch team, but Kibana appears to be displaying the data returned from elasticsearch correctly."}}