{"action":"closed","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/11916","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11916/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11916/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11916/events","html_url":"https://github.com/elastic/elasticsearch/issues/11916","id":91827502,"number":11916,"title":"The \"size\" and \"from\" of root of search JSON do not work with aggregation","user":{"login":"rusboy","id":3583960,"avatar_url":"https://avatars.githubusercontent.com/u/3583960?v=3","gravatar_id":"","url":"https://api.github.com/users/rusboy","html_url":"https://github.com/rusboy","followers_url":"https://api.github.com/users/rusboy/followers","following_url":"https://api.github.com/users/rusboy/following{/other_user}","gists_url":"https://api.github.com/users/rusboy/gists{/gist_id}","starred_url":"https://api.github.com/users/rusboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rusboy/subscriptions","organizations_url":"https://api.github.com/users/rusboy/orgs","repos_url":"https://api.github.com/users/rusboy/repos","events_url":"https://api.github.com/users/rusboy/events{/privacy}","received_events_url":"https://api.github.com/users/rusboy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-29T14:53:21Z","updated_at":"2015-06-30T09:40:27Z","closed_at":"2015-06-30T09:40:27Z","body":"Hey,\r\n\r\nI'm observing some strange behavior with aggregation. I'm using ES 1.6.\r\n```\r\n{\r\n  \"status\" : 200,\r\n  \"name\" : \"Honey Lemon\",\r\n  \"cluster_name\" : \"elasticsearch\",\r\n  \"version\" : {\r\n    \"number\" : \"1.6.0\",\r\n    \"build_hash\" : \"cdd3ac4dde4f69524ec0a14de3828cb95bbb86d0\",\r\n    \"build_timestamp\" : \"2015-06-09T13:36:34Z\",\r\n    \"build_snapshot\" : false,\r\n    \"lucene_version\" : \"4.10.4\"\r\n  },\r\n  \"tagline\" : \"You Know, for Search\"\r\n}\r\n```\r\n\r\nI've built search JSON where I used \"from\", \"size\" and aggregation. So, it looks like following code:\r\n```\r\n{\r\n  \"from\": 0,\r\n  \"size\": 5,\r\n  \"sort\" : [\r\n       { \"profile\" : {\"order\" : \"asc\"}}\r\n  ],\r\n  \"aggs\": {\r\n    \"genders\": {\r\n      \"terms\": {\r\n        \"field\": \"custom_field\",\r\n        \"order\" : { \"_term\" : \"asc\" }\r\n      },\r\n      \"aggs\": {\r\n                \"my_top_hits\": {\r\n                    \"top_hits\": {\r\n                       \"from\" : 0,\r\n                        \"sort\": [\r\n                            {\r\n                                \"count\": {\r\n                                    \"order\": \"asc\"\r\n                                }\r\n                            }\r\n                        ],\r\n                      \"size\" : 4  // I know, I can increase the value. But it's not solves issue anyway\r\n                    }\r\n                }\r\n            }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nMy expectations are, only 5 first documents of index are used for aggregation... However, I was surprised.. Aggregation results include all documents from index.\r\n\r\nI tried to add query tag in search JSON.. And I see, aggregation works only with part of documents that are \"provided\"/\"filtered\" by query..\r\nI think, \"from\" and \"size\" of root search JSON should cut list of documents for aggregations, similar with \r\n\r\n\r\nTask that I'm trying to solve is grouping documents by some field. Something like GROUP BY of MySQL. Some example from extjs could be find here http://docs.sencha.com/extjs/4.2.3/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#grouped-grid\r\n\r\nMy idea was, to use \"from\"/\"size\", for paging via aggregated data. In other words, I would be \"ask\" aggregation process only required for myself part of data. \r\nFor example, now I could be use \"size\" of terms aggregation.. but it means, I'll have N buckets with length <= the \"size\". But it's worse way..Because to show table I 'll use only number required for site documents. But, also.. site will received a lot of data that are not required. It can impact customer's PC (I mean memory) and enforce to wait data foo long time if I use big data\r\n\r\nSome questions are opened for myself:\r\n1. Is it feature or bug? ( If it's bug I can take a look.. would be great if you recommend where in code I should start)\r\n2. Possible, u know other way to group data by field.\r\n3. Could be results of several metric aggregation are joined to one array ?"}}