How to do "offset" on aggreation results

Hi,
I have problem with writing query in Elastic. I have 1 milion parts and daily statistic for them. What i want to do is display all parts in 1000 chunks. Generally table with download count :wink:
So query in sql would look like
'select count(id) from stats group by part limt 1000'
'select count(id) from stats group by part limt 1000 offset 1000'
And so on.
So in elastic i have to use aggregation but when i do i can`t use 'from' on it.

Does anybody has some advice on this ?

In ES there is no such thing as a count with a limit. The limit in ES is more of a pagination upper bound - from & size and is not include in the count aggregation.

Any how, I believe "limit" is not of significance in what you're trying to do. In your sql statement, if the results are more than 1000, the count will return 1000. If the count is less than 1000, it will return X, where X <=1000

GET products/_search
{
    "aggs" : {
        "myname_count" : { 
          "value_count" : { 
            "field" : "price" 
            
          } 
          
        }
    }
}

The above will return the count value of group price. If value_count returns more than 1000, then you just mentally note that is should be 1000. If it is less than 1000, you will know what that X value is.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.