{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/11419","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11419/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11419/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11419/events","html_url":"https://github.com/elastic/elasticsearch/issues/11419","id":82430323,"number":11419,"title":"Scroll scan query doesn't return all documents.","user":{"login":"developmentstudio","id":5364555,"avatar_url":"https://avatars.githubusercontent.com/u/5364555?v=3","gravatar_id":"","url":"https://api.github.com/users/developmentstudio","html_url":"https://github.com/developmentstudio","followers_url":"https://api.github.com/users/developmentstudio/followers","following_url":"https://api.github.com/users/developmentstudio/following{/other_user}","gists_url":"https://api.github.com/users/developmentstudio/gists{/gist_id}","starred_url":"https://api.github.com/users/developmentstudio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/developmentstudio/subscriptions","organizations_url":"https://api.github.com/users/developmentstudio/orgs","repos_url":"https://api.github.com/users/developmentstudio/repos","events_url":"https://api.github.com/users/developmentstudio/events{/privacy}","received_events_url":"https://api.github.com/users/developmentstudio/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/non-issue","name":"non-issue","color":"cfcfcf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-05-29T13:35:23Z","updated_at":"2015-08-18T12:03:50Z","closed_at":"2015-06-01T10:22:51Z","body":"Hi all, At the moment I am trying to scan and scroll my ES index to export all the data, but I noticed that not always all the documents are returned. In other words ES says I have 1.115.857 documents in my index, but my export contains 1.049.191 documents. Testing with an index with up to 900.000 document is working fine. Somebody that can explain this behavior?\r\n\r\nES is running on a CentOS machine with 6GB of RAM with a ES_HEAP_SIZE of 3GB."},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/132187270","html_url":"https://github.com/elastic/elasticsearch/issues/11419#issuecomment-132187270","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11419","id":132187270,"user":{"login":"lexand","id":927515,"avatar_url":"https://avatars.githubusercontent.com/u/927515?v=3","gravatar_id":"","url":"https://api.github.com/users/lexand","html_url":"https://github.com/lexand","followers_url":"https://api.github.com/users/lexand/followers","following_url":"https://api.github.com/users/lexand/following{/other_user}","gists_url":"https://api.github.com/users/lexand/gists{/gist_id}","starred_url":"https://api.github.com/users/lexand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lexand/subscriptions","organizations_url":"https://api.github.com/users/lexand/orgs","repos_url":"https://api.github.com/users/lexand/repos","events_url":"https://api.github.com/users/lexand/events{/privacy}","received_events_url":"https://api.github.com/users/lexand/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T12:03:50Z","updated_at":"2015-08-18T12:03:50Z","body":"Salutations\r\nhave the same issue but cannot determine why\r\n\r\nnewly created index\r\ninsert 50 random documents (one text field per each doc) with autogenerated _id\r\n\r\nSearch without scroll\r\n```PHP\r\n\t\t$res = $client->search(\r\n\t\t\t[\r\n\t\t\t\t'index'  => $index,\r\n\t\t\t\t'type'   => $type,\r\n\t\t\t\t'size'   => 100,\r\n\t\t\t\t'body'   => []\r\n\t\t\t]);\r\n\t\tprint_r(['total'    => $res['hits']['total'],\r\n\t\t         'returned' => count($res['hits']['hits']),\r\n\t\t         '_shards'  => $res['_shards']]);\r\n```\r\n```\r\nArray\r\n(\r\n    [total] => 50\r\n    [returned] => 50\r\n    [_shards] => Array\r\n        (\r\n            [total] => 3\r\n            [successful] => 3\r\n            [failed] => 0\r\n        )\r\n)\r\n```\r\n\r\nBut search with scroll returns next\r\n```PHP\r\n\t\t$res = $client->search(\r\n\t\t\t[\r\n\t\t\t\t'index'  => $index,\r\n\t\t\t\t'type'   => $type,\r\n\t\t\t\t'scroll' => '1m',\r\n\t\t\t\t'size'   => 10, // per shards, so I expect 30 results maximum. Where are they ?\r\n\t\t\t\t'body'   => []\r\n\t\t\t]);\r\n                $scrollId = $res['_scroll_id'];\r\n\t\tprint_r(...);\r\n                \r\n                $res = $client->scroll(['scroll_id' => $scrollId]);\r\n\t\tprint_r(...);\r\n                $res = $client->scroll(['scroll_id' => $scrollId]);\r\n\t\tprint_r(...);\r\n                $res = $client->scroll(['scroll_id' => $scrollId]);\r\n\t\tprint_r(...);\r\n```\r\n```\r\nArray\r\n(\r\n    [total] => 50\r\n    [returned] => 10\r\n    [_shards] => Array\r\n        (\r\n            [total] => 3\r\n            [successful] => 3\r\n            [failed] => 0\r\n        )\r\n\r\n)\r\nscroll 1\r\nArray\r\n(\r\n    [total] => 50\r\n    [returned] => 10\r\n    [_shards] => Array\r\n        (\r\n            [total] => 3\r\n            [successful] => 3\r\n            [failed] => 0\r\n        )\r\n\r\n)\r\nscroll 2\r\nArray\r\n(\r\n    [total] => 29\r\n    [returned] => 10\r\n    [_shards] => Array\r\n        (\r\n            [total] => 3\r\n            [successful] => 2\r\n            [failed] => 1\r\n            [failures] => Array\r\n                (\r\n                    [0] => Array\r\n                        (\r\n                            [status] => 404\r\n                            [reason] => SearchContextMissingException[No search context found for id [22]]\r\n                        )\r\n\r\n                )\r\n\r\n        )\r\n\r\n)\r\nscroll 3\r\nArray\r\n(\r\n    [total] => 2\r\n    [returned] => 2\r\n    [_shards] => Array\r\n        (\r\n            [total] => 3\r\n            [successful] => 1\r\n            [failed] => 2\r\n            [failures] => Array\r\n                (\r\n                    [0] => Array\r\n                        (\r\n                            [status] => 404\r\n                            [reason] => SearchContextMissingException[No search context found for id [22]]\r\n                        )\r\n\r\n                    [1] => Array\r\n                        (\r\n                            [status] => 404\r\n                            [reason] => SearchContextMissingException[No search context found for id [23]]\r\n                        )\r\n\r\n                )\r\n\r\n        )\r\n)\r\n```\r\n\r\nAnd totally 32 documents are returned\r\n\r\n```\r\nOpening index @ /var/lib/elasticsearch/elasticsearch/nodes/0/indices/test/0/index/\r\n\r\nSegments file=segments_3 numSegments=1 version=4.10.4 format= userData={sync_id=AU9AS-k-fF4_530OBpQo, translog_id=1439890621685}\r\n  1 of 1: name=_0 docCount=21\r\n    version=4.10.4\r\n    codec=Lucene410\r\n    compound=true\r\n    numFiles=3\r\n    size (MB)=0.024\r\n    diagnostics = {timestamp=1439890622956, os=Linux, os.version=4.1.4-100.fc21.x86_64, source=flush, lucene.version=4.10.4, os.arch=amd64, java.version=1.7.0_76, java.vendor=Oracle Corporation}\r\n    no deletions\r\n    test: open reader.........OK\r\n    test: check integrity.....OK\r\n    test: check live docs.....OK\r\n    test: fields..............OK [7 fields]\r\n    test: field norms.........OK [2 fields]\r\n    test: terms, freq, prox...OK [168 terms; 2078 terms/docs pairs; 2222 tokens]\r\n    test: stored fields.......OK [42 total field count; avg 2 fields per doc]\r\n    test: term vectors........OK [0 total vector count; avg 0 term/freq vector fields per doc]\r\n    test: docvalues...........OK [1 docvalues fields; 0 BINARY; 1 NUMERIC; 0 SORTED; 0 SORTED_NUMERIC; 0 SORTED_SET]\r\n\r\nNo problems were detected with this index.\r\n\r\nOpening index @ /var/lib/elasticsearch/elasticsearch/nodes/0/indices/test/1/index/\r\n\r\nSegments file=segments_3 numSegments=1 version=4.10.4 format= userData={sync_id=AU9AS-k_fF4_530OBpQp, translog_id=1439890621705}\r\n  1 of 1: name=_0 docCount=27\r\n    version=4.10.4\r\n    codec=Lucene410\r\n    compound=true\r\n    numFiles=3\r\n    size (MB)=0.026\r\n    diagnostics = {timestamp=1439890622962, os=Linux, os.version=4.1.4-100.fc21.x86_64, source=flush, lucene.version=4.10.4, os.arch=amd64, java.version=1.7.0_76, java.vendor=Oracle Corporation}\r\n    no deletions\r\n    test: open reader.........OK\r\n    test: check integrity.....OK\r\n    test: check live docs.....OK\r\n    test: fields..............OK [7 fields]\r\n    test: field norms.........OK [2 fields]\r\n    test: terms, freq, prox...OK [168 terms; 2398 terms/docs pairs; 2530 tokens]\r\n    test: stored fields.......OK [54 total field count; avg 2 fields per doc]\r\n    test: term vectors........OK [0 total vector count; avg 0 term/freq vector fields per doc]\r\n    test: docvalues...........OK [1 docvalues fields; 0 BINARY; 1 NUMERIC; 0 SORTED; 0 SORTED_NUMERIC; 0 SORTED_SET]\r\n\r\nNo problems were detected with this index.\r\n\r\nOpening index @ /var/lib/elasticsearch/elasticsearch/nodes/0/indices/test/2/index/\r\n\r\nSegments file=segments_3 numSegments=1 version=4.10.4 format= userData={sync_id=AU9AS-k_fF4_530OBpQq, translog_id=1439890621710}\r\n  1 of 1: name=_0 docCount=2\r\n    version=4.10.4\r\n    codec=Lucene410\r\n    compound=true\r\n    numFiles=3\r\n    size (MB)=0.007\r\n    diagnostics = {timestamp=1439890622865, os=Linux, os.version=4.1.4-100.fc21.x86_64, source=flush, lucene.version=4.10.4, os.arch=amd64, java.version=1.7.0_76, java.vendor=Oracle Corporation}\r\n    no deletions\r\n    test: open reader.........OK\r\n    test: check integrity.....OK\r\n    test: check live docs.....OK\r\n    test: fields..............OK [7 fields]\r\n    test: field norms.........OK [2 fields]\r\n    test: terms, freq, prox...OK [143 terms; 254 terms/docs pairs; 278 tokens]\r\n    test: stored fields.......OK [4 total field count; avg 2 fields per doc]\r\n    test: term vectors........OK [0 total vector count; avg 0 term/freq vector fields per doc]\r\n    test: docvalues...........OK [1 docvalues fields; 0 BINARY; 1 NUMERIC; 0 SORTED; 0 SORTED_NUMERIC; 0 SORTED_SET]\r\n\r\nNo problems were detected with this index.\r\n```\r\nES Version\r\n```JSON\r\n{\r\n  \"status\" : 200,\r\n  \"name\" : \"Temugin\",\r\n  \"cluster_name\" : \"elasticsearch\",\r\n  \"version\" : {\r\n    \"number\" : \"1.7.1\",\r\n    \"build_hash\" : \"b88f43fc40b0bcd7f173a1f9ee2e97816de80b19\",\r\n    \"build_timestamp\" : \"2015-07-29T09:54:16Z\",\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\nIndex settings\r\n```JSON\r\n{\r\n  \"test\" : {\r\n    \"aliases\" : { },\r\n    \"mappings\" : {\r\n      \"test\" : {\r\n        \"properties\" : {\r\n          \"text\" : {\r\n            \"type\" : \"string\"\r\n          }\r\n        }\r\n      }\r\n    },\r\n    \"settings\" : {\r\n      \"index\" : {\r\n        \"creation_date\" : \"1439890619858\",\r\n        \"uuid\" : \"0OgM42BBSVGjcd_z4mTKxw\",\r\n        \"number_of_replicas\" : \"1\",\r\n        \"number_of_shards\" : \"3\",\r\n        \"version\" : {\r\n          \"created\" : \"1070199\"\r\n        }\r\n      }\r\n    },\r\n    \"warmers\" : { }\r\n  }\r\n}\r\n```"}}