Elasticsearch: TotalHitCountCollector message for top hits aggregation can be improved

Created on 24 Apr 2015  路  10Comments  路  Source: elastic/elasticsearch

If you attempt to specify a size of 0 or -1 for a top hits aggregation, you will get this error:

IllegalArgumentException[numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count

Probably not a good idea to return all hits to begin with, but it will be nice to return a more intuitive message if one does attempt to set this to 0 or -1, etc..

:AnalyticAggregations >enhancement Analytics good first issue help wanted

All 10 comments

@ppf2 can you suggest one?

I think if size is set to 0 we should just return a hits that only contains a total count and if a negative value is specified we should fail with a parse exception or something like that.

I agree, it makes sense to allow size=0, and a parse error for size < 0 is helpful. Maybe indicate in the error message what is the range of size that is allowed (or even warn users about setting size to something very large like integer max, etc..)

When counting when the size is 0 is what we do for regular search operations. However for aggregations, you already know the match count anyway thanks to the parent aggregation, to I think it's right to raise an error is size is less than or equal to 0 as it's almost certainly a user error.

This would be useful to have size:0 allowed. Why? Because I want the max_score for each bucket which I can only get when I return at least 1 top_hit. I do not want to see the top_hit - I just want a report of all buckets, doc counts in each bucket, and max score. Is there another way to get max_score of each bucket? Also, I need min_score. Is there a way to get that @clintongormley ?
thanks.

@linkwoman you could use a max aggregation on a script that just consists of _score for that. This would also be much more efficient.

Pinging @elastic/es-analytics-geo

When counting when the size is 0 is what we do for regular search operations. However for aggregations, you already know the match count anyway thanks to the parent aggregation, to I think it's right to raise an error is size is less than or equal to 0 as it's almost certainly a user error.

@jpountz Is it possible to reference the match count in the same query or would I need to perform 2 requests? I would like to get all my hits, not just the top N

Probably because you assign an negative value to the from parameter, coz I 'm encounter the same mistake...

I cannot reproduce it in master anymore. I am getting the following error message:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "[from] must be greater than or equal to 0. Found [-1] in [top_tag_hits]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "[from] must be greater than or equal to 0. Found [-1] in [top_tag_hits]"
  },
  "status" : 400
}

If it is still reproducible somewhere, please free to reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abtpst picture abtpst  路  3Comments

jasontedor picture jasontedor  路  3Comments

rjernst picture rjernst  路  3Comments

ttaranov picture ttaranov  路  3Comments

dadoonet picture dadoonet  路  3Comments