Mangoski
Mangoski

Reputation: 2119

How to limit the result of Elasticsearch

I wrote an elasticsearch query to get only top 10 result in descending order

{

  "aggs": {
    "group_by_user": {
      "terms": {
        "field": "user.raw",
         "size": 10
      }
    }
  }
}

I am getting below error I am getting the following error

Result window is too large, from + size must be less than or equal to: [10000] but was [10250]

How to rephrase my query to get the exact result of what I am looking for it. I dont know where I am going wrong.

Thanks in advance.

Upvotes: 1

Views: 147

Answers (2)

adityasinghraghav
adityasinghraghav

Reputation: 534

Is there a field called size in your document ? Because if not that's not how you use from/size. If there is indeed a field named size mapped as a number, I don't see any reason this query shouldn't work, it should still give 10 results by default.

Anyways the correct way of using from/size is

{
  "from": 0, "size": 10,
  "aggs": {
    "group_by_user": {
      "terms": {
        "field": "user.raw",
      }
    }
  }
}

This will give you 10 results, ie. results from 0 with a size of 10

Upvotes: 0

Andrei Stefan
Andrei Stefan

Reputation: 52368

Not this size is the one to look for, but the one at the root of the query:

{
  "size": 10250,
  "aggs": {
    "group_by_user": {
      "terms": {
        "field": "user.raw",
         "size": 10
      }
    }
  }
}

The error message is about that one. Check your query and, potentially, any query parameters under the form ?size=10250....

Upvotes: 2

Related Questions