# IDs query returning incomplete results

**URL:** https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934
**Category:** Elasticsearch
**Created:** [April 13, 2018, 9:01am UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934 "2018-04-13T09:01:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cwinkler](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cwinkler](https://discuss.elastic.co/u/cwinkler)
#### Post date: [April 13, 2018, 9:01am UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/1 "2018-04-13T09:01:40Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [April 13, 2018, 9:52am UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/2 "2018-04-13T09:52:24Z")

</div>

Which version of Elasticsearch are you using?

---

<div class="post-metadata">

### Author: ![cwinkler](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cwinkler](https://discuss.elastic.co/u/cwinkler)
#### Post date: [April 13, 2018, 10:01am UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/3 "2018-04-13T10:01:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cwinkler](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cwinkler](https://discuss.elastic.co/u/cwinkler)
#### Post date: [April 18, 2018, 1:49pm UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/4 "2018-04-18T13:49:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [April 18, 2018, 2:43pm UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/5 "2018-04-18T14:43:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cwinkler](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@cwinkler](https://discuss.elastic.co/u/cwinkler)
#### Post date: [April 18, 2018, 3:01pm UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/6 "2018-04-18T15:01:36Z")

</div>

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": [
 							"LogMessage"
 						],
 						"values": [
 							"01e8430a-e1b2-1e7a-aa96-c1e943736030",
 							"01e8430a-e1b1-1804-9628-d5b9e12b0a84",
 							"01e8430a-e4af-1781-92ba-cff7229bf670",
 							"01e8430a-e1b3-13d6-9628-d5b9e12b0a84",
 							"01e8430a-e1b2-1f4e-badf-b7e530d25a2a",
 							"01e8430a-e1b4-1a4c-aa96-c1e943736030",
 							"01e8430a-e1b3-1fef-92ba-cff7229bf670",
 							"01e8430a-e1b1-1fb7-badf-b7e530d25a2a",
 							"01e8430a-e1b3-15b6-aa6a-3b4497e409fe",
 							"01e8430a-e1b4-1a79-aa6a-3b4497e409fe",
 							"01e8430a-e1b3-1ae7-9628-d5b9e12b0a84",
 							"01e8430a-e1b3-13d7-aa6a-3b4497e409fe",
 							"01e8430a-e1b1-1eeb-92ba-cff7229bf670",
 							"01e8430a-e1b3-1abc-92ba-cff7229bf670",
 							"01e8430a-e1b6-1a0a-aa6a-3b4497e409fe",
 							"01e8430a-e1b4-151b-aa96-c1e943736030",
 							"01e8430a-e3bc-1126-9a01-319778ddbf4e",
 							"01e8430a-e398-1ec7-bb4a-d9ce79562946",
 							"01e8430a-e28b-1b8d-bb4a-d9ce79562946",
 							"01e8430a-e4ed-15c0-bb4a-d9ce79562946",
 							"01e8430a-e1c0-112e-aa96-c1e943736030",
 							"01e8430a-e1bf-137d-aa96-c1e943736030",
 							"01e8430a-e1b1-1ee9-aa96-c1e943736030",
 							"01e8430a-e37a-1632-ac83-ff9b055f540e",
 							"01e8430a-e1f2-1507-bb4a-d9ce79562946"
 						],
 						"boost": 1.0
 					}
 				}
 			],
 			"disable_coord": false,
 			"adjust_pure_negative": true,
 			"boost": 1.0
 		}
 	},
 	"_source": {
 		"includes": [],
 		"excludes": [
 			"activities",
 			"transitions",
 			"plugins",
 			"rawTransitions"
 		]
 	}
 }
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 16, 2018, 3:01pm UTC](https://discuss.elastic.co/t/ids-query-returning-incomplete-results/127934/7 "2018-05-16T15:01:40Z")

</div>

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