IDs query returning incomplete results

I have a set of distinct document IDs.
I know for sure that these documents exist, because the IDs have been retrieved by some previous queries.

Now I'm executing an IDs query for these IDs.
However, the first execution of such query sometimes does not return complete results, i.e., some documents missing.
When I execute the same query a second time, the results are complete.
Setting size to the number of IDs or even a way larger number has no effect on this behavior.

Why does this happen?
And how can I force ES to return full results?

1 Like

Which version of Elasticsearch are you using?

We are currently using 5.5.3 but we saw this behavior even with 2.x

As I didn't get an answer so far, here is some more information.
The first requests use _source=false and just get the document IDs as results.

The second and problematic IDs query is meant for getting the details of some previous results using _source=true

Maybe the issue is related to that?

Can you perhaps show a minimal recreating script so we better can understand what the issue is?

The preparation is to store some documents with significant size (~10kB each), and then fetch those documents with the following query.
The query is logged from Java API in terms of SearchRequestBuilder.toString()

The issue seems to occur particularly when ES is freshly started, i.e., it may be related to some caching.

Invoking the query for the first time may return only ~20 results, and invoking again afterwards will give all 25 espected results.

 	"size": 25,
 	"timeout": "2m",
 	"query": {
 		"bool": {
			"filter": [{
 					"ids": {
 						"type": [
 						"values": [
 						"boost": 1.0
 			"disable_coord": false,
 			"adjust_pure_negative": true,
 			"boost": 1.0
 	"_source": {
 		"includes": [],
 		"excludes": [

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