{"action":"closed","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/28536","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/28536/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/28536/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/28536/events","html_url":"https://github.com/elastic/elasticsearch/issues/28536","id":294801752,"number":28536,"title":"Wrong percentile_ranks calculation","user":{"login":"martini97","id":18130319,"avatar_url":"https://avatars0.githubusercontent.com/u/18130319?v=4","gravatar_id":"","url":"https://api.github.com/users/martini97","html_url":"https://github.com/martini97","followers_url":"https://api.github.com/users/martini97/followers","following_url":"https://api.github.com/users/martini97/following{/other_user}","gists_url":"https://api.github.com/users/martini97/gists{/gist_id}","starred_url":"https://api.github.com/users/martini97/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martini97/subscriptions","organizations_url":"https://api.github.com/users/martini97/orgs","repos_url":"https://api.github.com/users/martini97/repos","events_url":"https://api.github.com/users/martini97/events{/privacy}","received_events_url":"https://api.github.com/users/martini97/received_events","type":"User","site_admin":false},"labels":[{"id":141141324,"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Search/Aggregations","name":":Search/Aggregations","color":"0e8a16","default":false},{"id":23173,"url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Ebug","name":">bug","color":"b60205","default":false}],"state":"closed","locked":false,"assignee":{"login":"colings86","id":236731,"avatar_url":"https://avatars0.githubusercontent.com/u/236731?v=4","gravatar_id":"","url":"https://api.github.com/users/colings86","html_url":"https://github.com/colings86","followers_url":"https://api.github.com/users/colings86/followers","following_url":"https://api.github.com/users/colings86/following{/other_user}","gists_url":"https://api.github.com/users/colings86/gists{/gist_id}","starred_url":"https://api.github.com/users/colings86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colings86/subscriptions","organizations_url":"https://api.github.com/users/colings86/orgs","repos_url":"https://api.github.com/users/colings86/repos","events_url":"https://api.github.com/users/colings86/events{/privacy}","received_events_url":"https://api.github.com/users/colings86/received_events","type":"User","site_admin":false},"assignees":[{"login":"colings86","id":236731,"avatar_url":"https://avatars0.githubusercontent.com/u/236731?v=4","gravatar_id":"","url":"https://api.github.com/users/colings86","html_url":"https://github.com/colings86","followers_url":"https://api.github.com/users/colings86/followers","following_url":"https://api.github.com/users/colings86/following{/other_user}","gists_url":"https://api.github.com/users/colings86/gists{/gist_id}","starred_url":"https://api.github.com/users/colings86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colings86/subscriptions","organizations_url":"https://api.github.com/users/colings86/orgs","repos_url":"https://api.github.com/users/colings86/repos","events_url":"https://api.github.com/users/colings86/events{/privacy}","received_events_url":"https://api.github.com/users/colings86/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2018-02-06T15:30:39Z","updated_at":"2018-03-22T19:44:03Z","closed_at":"2018-03-22T19:44:03Z","author_association":"NONE","body":"<!-- Bug report -->\r\n\r\n**Elasticsearch version** (`bin/elasticsearch --version`):\r\nVersion: 6.1.3, Build: af51318/2018-01-26T18:22:55.523Z, JVM: 1.8.0_16\r\n\r\n**Plugins installed**: []\r\n\r\n**JVM version** (`java -version`):\r\nopenjdk version \"1.8.0_161\"\r\nOpenJDK Runtime Environment (build 1.8.0_161-b14)\r\nOpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)\r\n\r\n**OS version** (`uname -a` if on a Unix-like system):\r\nLinux 053db24b9161 4.13.0-32-generic #35~16.04.1-Ubuntu SMP Thu Jan 25 10:13:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n**Description of the problem including expected versus actual behavior**:\r\nPercentile ranks returns incorrect value for nested aggregation.\r\nQuery that I'm using:\r\n```\r\ncurl -XGET \"http://elasticsearch:9200/questions/_search\" -H 'Content-Type: application/json' -d'\r\n{\r\n  \"size\": 0,\r\n  \"aggs\": {\r\n    \"player\": {\r\n      \"filter\": {\r\n        \"bool\": {\r\n          \"must\": [ { \"term\": { \"playerId\": 1 } } ]\r\n        }\r\n      },\r\n      \"aggs\": {\r\n        \"topics\": {\r\n          \"terms\": { \"field\": \"topicId\" },\r\n          \"aggs\": {\r\n            \"date\": {\r\n              \"date_histogram\": {\r\n                \"field\": \"date\",\r\n                \"interval\": \"day\"\r\n              },\r\n              \"aggs\": {\r\n                \"percentage\": {\r\n                  \"percentile_ranks\": {\r\n                    \"field\": \"correctAsInt\",\r\n                    \"values\": [ 50 ]\r\n                  }\r\n                }\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}'\r\n```\r\nResult:\r\n```\r\n{\r\n  \"took\": 3,\r\n  \"timed_out\": false,\r\n  \"_shards\": {\r\n    \"total\": 1,\r\n    \"successful\": 1,\r\n    \"skipped\": 0,\r\n    \"failed\": 0\r\n  },\r\n  \"hits\": {\r\n    \"total\": 70,\r\n    \"max_score\": 0,\r\n    \"hits\": []\r\n  },\r\n  \"aggregations\": {\r\n    \"player\": {\r\n      \"doc_count\": 60,\r\n      \"topics\": {\r\n        \"doc_count_error_upper_bound\": 0,\r\n        \"sum_other_doc_count\": 0,\r\n        \"buckets\": [\r\n          {\r\n            \"key\": 1,\r\n            \"doc_count\": 30,\r\n            \"date\": {\r\n              \"buckets\": [\r\n                {\r\n                  \"key_as_string\": \"2018-02-06T00:00:00.000Z\",\r\n                  \"key\": 1517875200000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 30\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-07T00:00:00.000Z\",\r\n                  \"key\": 1517961600000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 40\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-08T00:00:00.000Z\",\r\n                  \"key\": 1518048000000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 20\r\n                    }\r\n                  }\r\n                }\r\n              ]\r\n            }\r\n          },\r\n          {\r\n            \"key\": 2,\r\n            \"doc_count\": 30,\r\n            \"date\": {\r\n              \"buckets\": [\r\n                {\r\n                  \"key_as_string\": \"2018-02-06T00:00:00.000Z\",\r\n                  \"key\": 1517875200000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 70\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-07T00:00:00.000Z\",\r\n                  \"key\": 1517961600000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 60\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-08T00:00:00.000Z\",\r\n                  \"key\": 1518048000000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 0      <---- this is the only wrong value\r\n                    }\r\n                  }\r\n                }\r\n              ]\r\n            }\r\n          }\r\n        ]\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\nExpected result:\r\n```\r\n{\r\n  \"took\": 3,\r\n  \"timed_out\": false,\r\n  \"_shards\": {\r\n    \"total\": 1,\r\n    \"successful\": 1,\r\n    \"skipped\": 0,\r\n    \"failed\": 0\r\n  },\r\n  \"hits\": {\r\n    \"total\": 70,\r\n    \"max_score\": 0,\r\n    \"hits\": []\r\n  },\r\n  \"aggregations\": {\r\n    \"player\": {\r\n      \"doc_count\": 60,\r\n      \"topics\": {\r\n        \"doc_count_error_upper_bound\": 0,\r\n        \"sum_other_doc_count\": 0,\r\n        \"buckets\": [\r\n          {\r\n            \"key\": 1,\r\n            \"doc_count\": 30,\r\n            \"date\": {\r\n              \"buckets\": [\r\n                {\r\n                  \"key_as_string\": \"2018-02-06T00:00:00.000Z\",\r\n                  \"key\": 1517875200000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 30\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-07T00:00:00.000Z\",\r\n                  \"key\": 1517961600000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 40\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-08T00:00:00.000Z\",\r\n                  \"key\": 1518048000000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 20\r\n                    }\r\n                  }\r\n                }\r\n              ]\r\n            }\r\n          },\r\n          {\r\n            \"key\": 2,\r\n            \"doc_count\": 30,\r\n            \"date\": {\r\n              \"buckets\": [\r\n                {\r\n                  \"key_as_string\": \"2018-02-06T00:00:00.000Z\",\r\n                  \"key\": 1517875200000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 70\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-07T00:00:00.000Z\",\r\n                  \"key\": 1517961600000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 60\r\n                    }\r\n                  }\r\n                },\r\n                {\r\n                  \"key_as_string\": \"2018-02-08T00:00:00.000Z\",\r\n                  \"key\": 1518048000000,\r\n                  \"doc_count\": 10,\r\n                  \"percentage\": {\r\n                    \"values\": {\r\n                      \"50.0\": 80      <---- correct value\r\n                    }\r\n                  }\r\n                }\r\n              ]\r\n            }\r\n          }\r\n        ]\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nThe `correctAsInt` field used to be a boolean, but we changed so we could use this aggregation, it only receive 2 values: 100 if true or 0 if false.\r\n\r\n**Steps to reproduce**:\r\n\r\nPlease include a *minimal* but *complete* recreation of the problem, including\r\n(e.g.) index creation, mappings, settings, query etc.  The easier you make for\r\nus to reproduce it, the more likely that somebody will take the time to look at it.\r\n\r\n 1. Create mapping:\r\n```\r\ncurl -XPUT \"http://elasticsearch:9200/questions\" -H 'Content-Type: application/json' -d'\r\n{\r\n    \"mappings\": {\r\n        \"questions\": {\r\n            \"properties\": {\r\n                \"playerId\": { \"type\": \"integer\" },\r\n                \"topicId\": { \"type\": \"integer\" },\r\n                \"correctAsInt\": { \"type\": \"integer\" },\r\n                \"date\": { \"type\": \"date\" }\r\n            }\r\n        }\r\n    }\r\n}'\r\n```\r\n\r\n 2. Insert data:\r\n```\r\ncurl -XPOST \"http://elasticsearch:9200/_bulk\" -H 'Content-Type: application/json' -d'\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"0\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"1\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"2\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"3\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"4\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"5\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"6\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"7\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"8\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"9\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"10\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"11\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"12\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"13\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"14\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"15\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"16\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"17\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"18\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"19\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"20\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"21\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"22\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"23\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"24\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"25\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"26\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"27\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"28\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"29\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"30\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"31\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"32\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"33\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"34\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"35\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"36\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"37\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"38\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"39\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-06T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"40\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"41\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"42\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"43\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"44\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"45\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"46\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"47\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"48\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"49\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-07T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"50\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"51\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"52\" } }\r\n{ \"correctAsInt\": 100,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"53\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"54\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"55\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"56\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"57\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"58\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"59\" } }\r\n{ \"correctAsInt\": 0, \"date\": \"2018-02-08T12:16:40.816Z\", \"playerId\": 1, \"topicId\": 2 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"60\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"61\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"62\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"63\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"64\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"65\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"66\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"67\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"68\" } }\r\n{ \"correctAsInt\": 0,   \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n{ \"create\" : { \"_index\" : \"questions\", \"_type\" : \"questions\", \"_id\" : \"69\" } }\r\n{ \"correctAsInt\": 100, \"date\": \"2018-02-06T12:17:16.942Z\", \"playerId\": 2, \"topicId\": 1 }\r\n'\r\n```\r\n\r\n 3. Run the query:\r\n```\r\ncurl -XGET \"http://elasticsearch:9200/questions/_search\" -H 'Content-Type: application/json' -d'\r\n{\r\n  \"size\": 0,\r\n  \"aggs\": {\r\n    \"player\": {\r\n      \"filter\": {\r\n        \"bool\": {\r\n          \"must\": [ { \"term\": { \"playerId\": 1 } } ]\r\n        }\r\n      },\r\n      \"aggs\": {\r\n        \"topics\": {\r\n          \"terms\": { \"field\": \"topicId\" },\r\n          \"aggs\": {\r\n            \"date\": {\r\n              \"date_histogram\": {\r\n                \"field\": \"date\",\r\n                \"interval\": \"day\"\r\n              },\r\n              \"aggs\": {\r\n                \"percentage\": {\r\n                  \"percentile_ranks\": {\r\n                    \"field\": \"correctAsInt\",\r\n                    \"values\": [ 50 ]\r\n                  }\r\n                }\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}'\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"polyfractal"}}