<p dir="auto">ES 2.1<br>
<strong>Describe the feature</strong>:<br>
below query still get response:<br>
MatchAllQueryBuilder maq = QueryBuilders.matchAllQuery();<br>
SearchResponse sResponse = client.prepareSearch(indexName)<br>
.setSearchType(SearchType.SCAN)<br>
.setQuery(maq)<br>
.setSize(20000)<br>
.execute()<br>
.actionGet();</p>
<p dir="auto">better limit size for scroll search type the same way for search with max result window</p>
<p dir="auto"><strong>Elasticsearch version</strong>: 2.1.2 / 2.3.3</p>
<p dir="auto"><strong>JVM version</strong>: Java 8u91</p>
<p dir="auto"><strong>OS version</strong>: Ubuntu 16.04</p>
<p dir="auto"><strong>Description of the problem including expected versus actual behavior</strong>:<br>
Specifying a high value for <code class="notranslate">size=</code> when using scroll causes OOM.</p>
<p dir="auto">E.g: running <code class="notranslate">curl -XGET 'localhost:9200/*/_search?size=99999999'</code> results in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{&quot;error&quot;:{&quot;root_cause&quot;:[{&quot;type&quot;:&quot;query_phase_execution_exception&quot;,&quot;reason&quot;:&quot;Result window is too large, from + size must be less than or equal to: [10000] but was [99999999]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level parameter.&quot;}],&quot;type&quot;:&quot;search_phase_execution_exception&quot;,&quot;reason&quot;:&quot;all shards failed&quot;,&quot;phase&quot;:&quot;query&quot;,&quot;grouped&quot;:true,&quot;failed_shards&quot;:[{&quot;shard&quot;:0,&quot;index&quot;:&quot;.triggered_watches&quot;,&quot;node&quot;:&quot;qmVwvx_9RDqdn6QG8n8SKQ&quot;,&quot;reason&quot;:{&quot;type&quot;:&quot;query_phase_execution_exception&quot;,&quot;reason&quot;:&quot;Result window is too large, from + size must be less than or equal to: [10000] but was [99999999]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level parameter.&quot;}}]},&quot;status&quot;:500}"><pre class="notranslate"><code class="notranslate">{"error":{"root_cause":[{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [99999999]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level parameter."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":".triggered_watches","node":"qmVwvx_9RDqdn6QG8n8SKQ","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [99999999]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level parameter."}}]},"status":500}
</code></pre></div>
<p dir="auto">But when running <code class="notranslate">curl -XGET 'localhost:9200/*/_search?scroll=8m&amp;size=99999999</code>, the high value for <code class="notranslate">size=</code> is accepted, causing the node running OOM.</p>
<p dir="auto"><strong>Steps to reproduce</strong>:</p>
<ol dir="auto">
<li>Start ES</li>
<li>Run <code class="notranslate">curl -XGET 'localhost:9200/*/_search?scroll=8m&amp;size=99999999</code></li>
<li>Node runs OOM</li>
</ol>
<p dir="auto"><strong>Provide logs (if relevant)</strong>:</p>
<p dir="auto">Logs when calling <code class="notranslate">_search?scroll=8m&amp;size=99999999</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2016-07-04 13:34:08,734][INFO ][monitor.jvm              ] [Doctor Glitternight] [gc][young][1107][34] duration [781ms], collections [1]/[1.4s], total [781ms]/[7.7s], memory [440.3mb]-&gt;[394.6mb]/[990.7mb], all_pools {[young] [172.7mb]-&gt;[1mb]/[266.2mb]}{[survivor] [33.2mb]-&gt;[33.2mb]/[33.2mb]}{[old] [234.3mb]-&gt;[360.3mb]/[691.2mb]}
[2016-07-04 13:36:00,540][WARN ][rest.suppressed          ] /*/_search Params: {pretty=, size=99999999, scroll=8m, index=*}
java.lang.OutOfMemoryError: Java heap space
    at org.elasticsearch.cache.recycler.PageCacheRecycler$1.newInstance(PageCacheRecycler.java:102)
    at org.elasticsearch.cache.recycler.PageCacheRecycler$1.newInstance(PageCacheRecycler.java:99)
    at org.elasticsearch.common.recycler.DequeRecycler.obtain(DequeRecycler.java:53)
    at org.elasticsearch.common.recycler.AbstractRecycler.obtain(AbstractRecycler.java:33)
    at org.elasticsearch.common.recycler.DequeRecycler.obtain(DequeRecycler.java:28)
    at org.elasticsearch.common.recycler.FilterRecycler.obtain(FilterRecycler.java:39)
    at org.elasticsearch.common.recycler.Recyclers$3.obtain(Recyclers.java:119)
    at org.elasticsearch.common.recycler.FilterRecycler.obtain(FilterRecycler.java:39)
    at org.elasticsearch.cache.recycler.PageCacheRecycler.bytePage(PageCacheRecycler.java:150)
    at org.elasticsearch.common.util.AbstractBigArray.newBytePage(AbstractBigArray.java:108)
    at org.elasticsearch.common.util.BigByteArray.resize(BigByteArray.java:140)
    at org.elasticsearch.common.util.BigArrays.resizeInPlace(BigArrays.java:425)
    at org.elasticsearch.common.util.BigArrays.resize(BigArrays.java:472)
    at org.elasticsearch.common.util.BigArrays.grow(BigArrays.java:489)
    at org.elasticsearch.common.io.stream.BytesStreamOutput.ensureCapacity(BytesStreamOutput.java:160)
    at org.elasticsearch.common.io.stream.BytesStreamOutput.writeBytes(BytesStreamOutput.java:90)
    at org.elasticsearch.common.io.stream.StreamOutput.write(StreamOutput.java:299)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:2003)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:597)
    at com.fasterxml.jackson.core.util.DefaultIndenter.writeIndentation(DefaultIndenter.java:94)
    at com.fasterxml.jackson.core.util.DefaultPrettyPrinter.writeObjectEntrySeparator(DefaultPrettyPrinter.java:307)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator._writePPFieldName(UTF8JsonGenerator.java:354)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:181)
    at com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:1557)
    at com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:1566)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.copyCurrentStructure(JsonXContentGenerator.java:425)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.copyRawValue(JsonXContentGenerator.java:410)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeRawField(JsonXContentGenerator.java:363)
    at org.elasticsearch.common.xcontent.XContentBuilder.rawField(XContentBuilder.java:914)
    at org.elasticsearch.common.xcontent.XContentHelper.writeRawField(XContentHelper.java:378)
    at org.elasticsearch.search.internal.InternalSearchHit.toXContent(InternalSearchHit.java:476)
    at org.elasticsearch.search.internal.InternalSearchHits.toXContent(InternalSearchHits.java:184)"><pre class="notranslate"><code class="notranslate">[2016-07-04 13:34:08,734][INFO ][monitor.jvm              ] [Doctor Glitternight] [gc][young][1107][34] duration [781ms], collections [1]/[1.4s], total [781ms]/[7.7s], memory [440.3mb]-&gt;[394.6mb]/[990.7mb], all_pools {[young] [172.7mb]-&gt;[1mb]/[266.2mb]}{[survivor] [33.2mb]-&gt;[33.2mb]/[33.2mb]}{[old] [234.3mb]-&gt;[360.3mb]/[691.2mb]}
[2016-07-04 13:36:00,540][WARN ][rest.suppressed          ] /*/_search Params: {pretty=, size=99999999, scroll=8m, index=*}
java.lang.OutOfMemoryError: Java heap space
    at org.elasticsearch.cache.recycler.PageCacheRecycler$1.newInstance(PageCacheRecycler.java:102)
    at org.elasticsearch.cache.recycler.PageCacheRecycler$1.newInstance(PageCacheRecycler.java:99)
    at org.elasticsearch.common.recycler.DequeRecycler.obtain(DequeRecycler.java:53)
    at org.elasticsearch.common.recycler.AbstractRecycler.obtain(AbstractRecycler.java:33)
    at org.elasticsearch.common.recycler.DequeRecycler.obtain(DequeRecycler.java:28)
    at org.elasticsearch.common.recycler.FilterRecycler.obtain(FilterRecycler.java:39)
    at org.elasticsearch.common.recycler.Recyclers$3.obtain(Recyclers.java:119)
    at org.elasticsearch.common.recycler.FilterRecycler.obtain(FilterRecycler.java:39)
    at org.elasticsearch.cache.recycler.PageCacheRecycler.bytePage(PageCacheRecycler.java:150)
    at org.elasticsearch.common.util.AbstractBigArray.newBytePage(AbstractBigArray.java:108)
    at org.elasticsearch.common.util.BigByteArray.resize(BigByteArray.java:140)
    at org.elasticsearch.common.util.BigArrays.resizeInPlace(BigArrays.java:425)
    at org.elasticsearch.common.util.BigArrays.resize(BigArrays.java:472)
    at org.elasticsearch.common.util.BigArrays.grow(BigArrays.java:489)
    at org.elasticsearch.common.io.stream.BytesStreamOutput.ensureCapacity(BytesStreamOutput.java:160)
    at org.elasticsearch.common.io.stream.BytesStreamOutput.writeBytes(BytesStreamOutput.java:90)
    at org.elasticsearch.common.io.stream.StreamOutput.write(StreamOutput.java:299)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:2003)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeRaw(UTF8JsonGenerator.java:597)
    at com.fasterxml.jackson.core.util.DefaultIndenter.writeIndentation(DefaultIndenter.java:94)
    at com.fasterxml.jackson.core.util.DefaultPrettyPrinter.writeObjectEntrySeparator(DefaultPrettyPrinter.java:307)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator._writePPFieldName(UTF8JsonGenerator.java:354)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:181)
    at com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:1557)
    at com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:1566)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.copyCurrentStructure(JsonXContentGenerator.java:425)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.copyRawValue(JsonXContentGenerator.java:410)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeRawField(JsonXContentGenerator.java:363)
    at org.elasticsearch.common.xcontent.XContentBuilder.rawField(XContentBuilder.java:914)
    at org.elasticsearch.common.xcontent.XContentHelper.writeRawField(XContentHelper.java:378)
    at org.elasticsearch.search.internal.InternalSearchHit.toXContent(InternalSearchHit.java:476)
    at org.elasticsearch.search.internal.InternalSearchHits.toXContent(InternalSearchHits.java:184)
</code></pre></div>
<p dir="auto"><strong>Describe the feature</strong>:</p>