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

Once in a while i get the following error:

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

The query is the following, with varying 'from', but never larger than 750:

 {
    	"track_total_hits": true,
    	"size": 15,
    	"from": 750,
    	"sort": [
    		{
    			"_score": {
    				"order": "desc"
    			}
    		},
    		{
    			"sortDate": {
    				"order": "desc"
    			}
    		}
    	],
    	"query": {
    		"function_score": {
    			"boost_mode": "sum",
    			"query": {
    				"bool": {
    					"filter": [
    						{
    							"match_all": {}
    						}
    					],
    					"must": []
    				}
    			},
    			"functions": [
    				{
    					"weight": 5.0
    				},
    				{
    					"weight": 1.0
    				},
    				{
    					"filter": {
    						"nested": {
    							"path": "addOns",
    							"query": {
    								"bool": {
    									"filter": [
    										{
    											"terms": {
    												"addOns.addOnID": [
    													8,
    													10
    												]
    											}
    										},
    										{
    											"range": {
    												"addOns.startDate": {
    													"lte": "2020-04-04T15:56:16.8498491+02:00"
    												}
    											}
    										},
    										{
    											"range": {
    												"addOns.finishDate": {
    													"gte": "2020-04-04T15:56:16.8498491+02:00"
    												}
    											}
    										}
    									]
    								}
    							}
    						}
    					},
    					"weight": 10.0
    				}
    			]
    		}
    	}
    }

I have increased the index to "max_result_window": "50000".
It is a standalone installation v. 7.5.2
The index has 1 shard and 0 replica.
The index never have more than 30.000 documents.

Why do the server throw Bad Request: "numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count" ?

can you share a full stack trace? You can use the error_trace=true parameter, see https://www.elastic.co/guide/en/elasticsearch/reference/7.6/common-options.html#common-options-error-options

Why did you change the max result window, if your from never exceeds 750?

Also, is the query you are running or just a part of it?

The query is the complete query.

I increased "max_result_window" because i needed to support some legacy views, where the user can go to page 1300. It is not optimal, but it is a move away from a sql solution, so not all can be changed at once, and has to be gradually rewritten. Since we are not talking millions of documents, i was not worried.

I'm guessing, this is the part i am hitting:

It is only, once in a while i get these errors. I will enable the stacktrace option in production.

D'oh, i found the error.

It is somehow possible for some users to set a negative "from". in a specific view.

Good find, I think the handling there should be improved to avoid confusion... I'll open an issue for that.

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