Limit query not working for me (JSON)

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,

Hi,

you do not mention your Elasticsearch version but note that limit filter is deprecated with 2.0 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) to limit the number of results per shard:

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

Daniel

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