# Missing result using scroll in java API

**URL:** <https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063>\
**Category:** Elasticsearch\
**Created:** [April 6, 2018, 9:57am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063 "2018-04-06T09:57:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kchrusciel](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@kchrusciel](https://discuss.elastic.co/u/kchrusciel)\
**Post date:** [April 6, 2018, 9:57am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/1 "2018-04-06T09:57:07Z")

</div>

Hi,

I use Java API to works with ES. When I start using scroll API like that:

```
SearchResponse response = client.prepareSearch()
                            .setIndices(indexName)
                            .setTypes(type)
                            .setSearchType(SearchType.DEFAULT)
                            .setScroll(TimeValue.timeValueMinutes(1));
                            .setSize(LogEntryStorage.SCROLL_PAGE_SIZE)
                            .setExplain(true)
                            .execute().actionGet()

response = srb.execute().actionGet();
response = client.prepareSearchScroll(response.getScrollId())
                            .setScroll(TimeValue.timeValueMinutes(1)).execute().actionGet();

```

The result of response.getHits().getHits() is empty but response.getHits().getTotalHits() has number which is correct. How to get this values ? I need to close or refresh scroll somehow?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2018, 10:11am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/2 "2018-04-06T10:11:48Z")

</div>

There is no query apparently, right?  
So it's a match\_all here.

I'd first remove `.setExplain(true)` as it does not bring any value and might slow down your process anyway.

If you run one first time this, and have totalHits \> 0 then you should have something in the `response.getHits().getHits()` I think.

Are you sure you did not run it a second time but there are no more records available?

---

<div class="post-metadata">

**Author:** ![kchrusciel](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@kchrusciel](https://discuss.elastic.co/u/kchrusciel)\
**Post date:** [April 6, 2018, 10:15am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/3 "2018-04-06T10:15:33Z")

</div>

Hi David

I see the problem, without scroll the total number of hits is 139.  
When I change setSize to 200 then in scroll getHits is 0  
but when i change setSize to number lower than totalHits for example 20, then each  
hit on scroll i have bunch of date with 20 results.

It looks like a bug when setSize is higher than total size.

> Are you sure you did not run it a second time but there are no more records available?

Yes, I'm sure

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2018, 10:26am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/4 "2018-04-06T10:26:54Z")

</div>

I'm surprised. Which version is that?

---

<div class="post-metadata">

**Author:** ![kchrusciel](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@kchrusciel](https://discuss.elastic.co/u/kchrusciel)\
**Post date:** [April 6, 2018, 10:27am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/5 "2018-04-06T10:27:17Z")

</div>

6.2.2

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2018, 10:27am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/6 "2018-04-06T10:27:56Z")

</div>

Can you reproduce it with just some REST commands? From Kibana Console?

---

<div class="post-metadata">

**Author:** ![kchrusciel](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@kchrusciel](https://discuss.elastic.co/u/kchrusciel)\
**Post date:** [April 6, 2018, 10:32am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/7 "2018-04-06T10:32:29Z")

</div>

Unfortunately not now.  
P.S Great presentation on CodeEurope in 2017 in Cracow 😉

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2018, 10:35am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/8 "2018-04-06T10:35:52Z")

</div>

Haha! Thank you! I'll be back at CodeEurope in Poznan in June 12th. 😛

---

<div class="post-metadata">

**Author:** ![kchrusciel](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@kchrusciel](https://discuss.elastic.co/u/kchrusciel)\
**Post date:** [April 6, 2018, 10:42am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/9 "2018-04-06T10:42:36Z")

</div>

Do you have any possibility to check/test this strange behavior?  
Or how to check it on Kibana? How to create scroll?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 6, 2018, 11:52am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/10 "2018-04-06T11:52:31Z")

</div>

I tried this on 6.2.3:

```auto
DELETE test
POST test/doc/_bulk
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
{ "index": {} }
{ "foo": "bar" }
POST test/_search?scroll=1m
{
    "size": 100
}

```

It works well:

```auto
{
  "_scroll_id": "DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAAFXFnJBbWhNdEtXU2MyTktwVFVjWGhiNVEAAAAAAAABVhZyQW1oTXRLV1NjMk5LcFRVY1hoYjVRAAAAAAAAAVgWckFtaE10S1dTYzJOS3BUVWNYaGI1UQAAAAAAAAFZFnJBbWhNdEtXU2MyTktwVFVjWGhiNVEAAAAAAAABWhZyQW1oTXRLV1NjMk5LcFRVY1hoYjVR",
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 17,
    "max_score": 1,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "iO3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "ku3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "iu3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "je3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "kO3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "k-3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "ie3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "i-3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "ju3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "lO3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "lu3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "l-3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "mO3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "jO3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "j-3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "ke3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "test",
        "_type": "doc",
        "_id": "le3GmmIBFZyT-UHdSJyi",
        "_score": 1,
        "_source": {
          "foo": "bar"
        }
      }
    ]
  }
}

```

---

<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 4, 2018, 11:52am UTC](https://discuss.elastic.co/t/missing-result-using-scroll-in-java-api/127063/11 "2018-05-04T11:52:40Z")

</div>

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