How to sort and then apply a limit filter in Elast

2019-07-31 17:15发布

I want to sort the results according to a specific field AND THEN apply the limit filter.

A simple common example would be a SQL query like select name from users order by name limit 100 would have returned the sorted results limited by 100.

I tried the same in Elasticsearch. However, this is not happening. It first applies the limits AND THEN sorts which is giving me undesired results. Can anyone point me what I am doing wrong ? This is the query I am currently using.

{
  "sort": [
    "full_name"
  ],
  "filter": {
    "limit": {
      "value": 100
    }
  }
}

2条回答
祖国的老花朵
3楼-- · 2019-07-31 17:37

The limit filter works on each shard first and then results are merged on one of the nodes. If you have more than one shard, that can produce interesting results. I think, as Gabbar already mentioned, what you are looking for is the "size" parameter.

查看更多
登录 后发表回答