Issue 1:
ES 2.1

Describe the feature:

below query still get response:

MatchAllQueryBuilder maq = QueryBuilders.matchAllQuery();

SearchResponse sResponse = client.prepareSearch(indexName)

.setSearchType(SearchType.SCAN)

.setQuery(maq)

.setSize(20000)

.execute()

.actionGet();

better limit size for scroll search type the same way for search with max result window

Issue 2:
Elasticsearch version: 2.1.2 / 2.3.3

JVM version: Java 8u91

OS version: Ubuntu 16.04

Description of the problem including expected versus actual behavior:

Specifying a high value for size= when using scroll causes OOM.

E.g: running curl -XGET 'localhost:9200/*/_search?size=99999999' results in:

{"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}

But when running curl -XGET 'localhost:9200/*/_search?scroll=8m&size=99999999, the high value for size= is accepted, causing the node running OOM.

Steps to reproduce:

Start ES

Run curl -XGET 'localhost:9200/*/_search?scroll=8m&size=99999999

Node runs OOM

Provide logs (if relevant):

Logs when calling _search?scroll=8m&size=99999999

[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]->[394.6mb]/[990.7mb], all_pools {[young] [172.7mb]->[1mb]/[266.2mb]}{[survivor] [33.2mb]->[33.2mb]/[33.2mb]}{[old] [234.3mb]->[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)

Describe the feature: