# Limit query not working for me (JSON)

**URL:** https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679
**Category:** Elasticsearch
**Created:** [February 25, 2016, 8:13am UTC](https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679 "2016-02-25T08:13:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mathaxx](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Mathaxx](https://discuss.elastic.co/u/Mathaxx)
#### Post date: [February 25, 2016, 8:13am UTC](https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679/1 "2016-02-25T08:13:17Z")

</div>

Hi,

My cluster configuration :

- 2 nodes

My index settings are :

- 3 primary shard
- 1 replica

I would like get 2 documents on each shard so I use this request :

> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "limit": {  
> "value": 2  
> }  
> }  
> }  
> }  
> }

So I suppose I should have 4 or 6 results, but I have 10 results.

> {  
> "took": 1118,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 3,  
> "successful": 3,  
> "failed": 0  
> },  
> "hits": {  
> "total": 50102,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4bjGzeyhS1lrlkN",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4brGzeyhS1lrlkP",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4c\_GzeyhS1lrlkV",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4dTGzeyhS1lrlkX",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4dgGzeyhS1lrlkZ",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH4dsGzeyhS1lrlkd",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH55sGzeyhS1lrlkr",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH55xGzeyhS1lrlkt",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH56oGzeyhS1lrlky",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> },  
> {  
> "\_index": "index",  
> "\_type": "type",  
> "\_id": "AVMPH3S7GzeyhS1lrlj5",  
> "\_score": 1,  
> "fields": {  
> "name": [  
> "value"  
> ]  
> }  
> }  
> ]  
> }  
> }

I don't understand why... if you have any idea ?

Thanks,

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [March 1, 2016, 10:11am UTC](https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679/2 "2016-03-01T10:11:14Z")

</div>

Hi,

you do not mention your Elasticsearch version but note that [limit filter is deprecated with 2.0](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/breaking_20_query_dsl_changes.html#_literal_limit_literal_filter_deprecated) and is essentially a no-op. I suspect you get 10 results because that is the default of `size`. You can use the `terminate_after` query parameter (see [docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/search-request-body.html)) to limit the number of results per shard:

```auto
GET /_search?terminate_after=2
{
   "query": {
      "match_all": {}
   }
}

```

Daniel

---

<div class="post-metadata">

### Author: ![Mathaxx](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Mathaxx](https://discuss.elastic.co/u/Mathaxx)
#### Post date: [March 1, 2016, 10:48am UTC](https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679/3 "2016-03-01T10:48:54Z")

</div>

Thank you, I did not see this option.  
It's perfect for me.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/limit-query-not-working-for-me-json/42679/4 "2017-07-05T23:12:34Z")

</div>


