# Bug when scrolling?

**URL:** <https://discuss.elastic.co/t/bug-when-scrolling/3901>\
**Category:** Elasticsearch\
**Created:** [February 8, 2011, 8:27pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901 "2011-02-08T20:27:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 8, 2011, 8:27pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/1 "2011-02-08T20:27:52Z")

</div>

Hi,

I simply want a functionality to reindex my docs currently indexed.  
Has someone some code for this 🙂 ?

There is a problem either in my code or in ES when doing some  
'overwriting' updates and then scrolling. Please see this out-of-the-  
box runnable gist:

> <https://gist.github.com/karussell/817094>

Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
documents returned???

Regards,  
Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 8, 2011, 8:29pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/2 "2011-02-08T20:29:16Z")

</div>

the problem does not occur for

put("index.number\_of\_shards", 1)

but does for shards\>1

On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> Hi,
> 
> I simply want a functionality to reindex my docs currently indexed.  
> Has someone some code for this 🙂 ?
> 
> There is a problem either in my code or in ES when doing some  
> 'overwriting' updates and then scrolling. Please see this out-of-the-  
> box runnable gist:
> 
> [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> 
> Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> documents returned???
> 
> Regards,  
> Peter.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 8, 2011, 9:44pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/3 "2011-02-08T21:44:04Z")

</div>

Heya,

I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.

I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.

Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).

-shay.banon  
On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:

> the problem does not occur for
> 
> put("index.number\_of\_shards", 1)
> 
> but does for shards\>1
> 
> On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> 
> > Hi,
> > 
> > I simply want a functionality to reindex my docs currently indexed.  
> > Has someone some code for this 🙂 ?
> > 
> > There is a problem either in my code or in ES when doing some  
> > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > box runnable gist:
> > 
> > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> > 
> > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > documents returned???
> > 
> > Regards,  
> > Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 8, 2011, 10:07pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/4 "2011-02-08T22:07:46Z")

</div>

> So, in your case, create and add it directly to a BulkRequestBuilder.

ok. what's so expensive to create that jsonBuilder?

> safeJsonBuilder

do you mean?  
XContentBuilder docBuilder =  
JsonXContent.unCachedContentBuilder().startObject();

> Also, scrolling is not the best way to reindex the data

so, how would you do this at the moment. would you use simple search  
(e.g. with a date filter) instead scrolling?

Regards,  
Peter.

On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Heya,
> 
> I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> 
> Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> 
> -shay.banon
> 
> On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> 
> > the problem does not occur for
> 
> > put("index.number\_of\_shards", 1)
> 
> > but does for shards\>1
> 
> > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > 
> > > Hi,
> 
> > > I simply want a functionality to reindex my docs currently indexed.  
> > > Has someone some code for this 🙂 ?
> 
> > > There is a problem either in my code or in ES when doing some  
> > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > box runnable gist:
> 
> > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> 
> > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > documents returned???
> 
> > > Regards,  
> > > Peter.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 8, 2011, 10:23pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/5 "2011-02-08T22:23:11Z")

</div>

On Wednesday, February 9, 2011 at 12:07 AM, Karussell wrote:  
So, in your case, create and add it directly to a BulkRequestBuilder.

> ok. what's so expensive to create that jsonBuilder?  
> Its not a question of expensive, but the byte buffer that is behind it is being reused on a thread local to reduce byte copying.
> 
> > safeJsonBuilder
> 
> do you mean?  
> XContentBuilder docBuilder =  
> JsonXContent.unCachedContentBuilder().startObject();  
> Yea, that is there as well. I added safeJsonBuilder that delegates to that one.
> 
> > Also, scrolling is not the best way to reindex the data
> 
> so, how would you do this at the moment. would you use simple search  
> (e.g. with a date filter) instead scrolling?  
> You will have the same problem with search and doing pagination using from / size. Thats why the scan type is needed. The overhead does not come from the scrolling implementation, but from how search is executed when it needs to do a sort in lucene, and when its distributed.
> 
> Regards,  
> Peter.
> 
> On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Heya,
> > 
> > I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> > 
> > I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> > 
> > Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> > 
> > -shay.banon
> > 
> > On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> > 
> > > the problem does not occur for
> > 
> > > put("index.number\_of\_shards", 1)
> > 
> > > but does for shards\>1
> > 
> > > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > > 
> > > > Hi,
> > 
> > > > I simply want a functionality to reindex my docs currently indexed.  
> > > > Has someone some code for this 🙂 ?
> > 
> > > > There is a problem either in my code or in ES when doing some  
> > > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > > box runnable gist:
> > 
> > > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> > 
> > > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > > documents returned???
> > 
> > > > Regards,  
> > > > Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 9, 2011, 5:06pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/6 "2011-02-09T17:06:54Z")

</div>

Hi Shay,

thanks for your answers! Do you know where the flaw could come from? I  
would like to investigate/fix it as I'm unsure if reindexing works  
even with this flaw ...

> you will have the same problem with search and doing pagination using from / size

Does it mean that if I want docs from pages A..B then ES has to use  
memory for 0..B ?

Could I overcome this problem with additional filter queries if I know  
how to split up my data - e.g. based on date?

Would the scan type be without scoring (I don't need that)?

Regards,  
Peter.

On 8 Feb., 23:23, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> On Wednesday, February 9, 2011 at 12:07 AM, Karussell wrote:
> 
> So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > ok. what's so expensive to create that jsonBuilder?
> 
> Its not a question of expensive, but the byte buffer that is behind it is being reused on a thread local to reduce byte copying.
> 
> > > safeJsonBuilder
> 
> > do you mean?  
> > XContentBuilder docBuilder =  
> > JsonXContent.unCachedContentBuilder().startObject();
> 
> Yea, that is there as well. I added safeJsonBuilder that delegates to that one.
> 
> > > Also, scrolling is not the best way to reindex the data
> 
> > so, how would you do this at the moment. would you use simple search  
> > (e.g. with a date filter) instead scrolling?
> 
> You will have the same problem with search and doing pagination using from / size. Thats why the scan type is needed. The overhead does not come from the scrolling implementation, but from how search is executed when it needs to do a sort in lucene, and when its distributed.
> 
> > Regards,  
> > Peter.
> 
> > On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Heya,
> 
> > > I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > > I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> 
> > > Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> 
> > > -shay.banon
> 
> > > On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> > > 
> > > > the problem does not occur for
> 
> > > > put("index.number\_of\_shards", 1)
> 
> > > > but does for shards\>1
> 
> > > > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > > > 
> > > > > Hi,
> 
> > > > > I simply want a functionality to reindex my docs currently indexed.  
> > > > > Has someone some code for this 🙂 ?
> 
> > > > > There is a problem either in my code or in ES when doing some  
> > > > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > > > box runnable gist:
> 
> > > > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> 
> > > > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > > > documents returned???
> 
> > > > > Regards,  
> > > > > Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 9, 2011, 6:47pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/7 "2011-02-09T18:47:26Z")

</div>

hmmh, when I'm doing an 'implicit search' (\_all??) it works correctly:

// for (String fromIndex : indexList) {  
String fromIndex = "";  
SearchResponse rsp = client.prepareSearch().  
...

On 9 Feb., 18:06, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> Hi Shay,
> 
> thanks for your answers! Do you know where the flaw could come from? I  
> would like to investigate/fix it as I'm unsure if reindexing works  
> even with this flaw ...
> 
> > you will have the same problem with search and doing pagination using from / size
> 
> Does it mean that if I want docs from pages A..B then ES has to use  
> memory for 0..B ?
> 
> Could I overcome this problem with additional filter queries if I know  
> how to split up my data - e.g. based on date?
> 
> Would the scan type be without scoring (I don't need that)?
> 
> Regards,  
> Peter.
> 
> On 8 Feb., 23:23, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > On Wednesday, February 9, 2011 at 12:07 AM, Karussell wrote:
> 
> > So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > > ok. what's so expensive to create that jsonBuilder?
> 
> > Its not a question of expensive, but the byte buffer that is behind it is being reused on a thread local to reduce byte copying.
> 
> > > > safeJsonBuilder
> 
> > > do you mean?  
> > > XContentBuilder docBuilder =  
> > > JsonXContent.unCachedContentBuilder().startObject();
> 
> > Yea, that is there as well. I added safeJsonBuilder that delegates to that one.
> 
> > > > Also, scrolling is not the best way to reindex the data
> 
> > > so, how would you do this at the moment. would you use simple search  
> > > (e.g. with a date filter) instead scrolling?
> 
> > You will have the same problem with search and doing pagination using from / size. Thats why the scan type is needed. The overhead does not come from the scrolling implementation, but from how search is executed when it needs to do a sort in lucene, and when its distributed.
> 
> > > Regards,  
> > > Peter.
> 
> > > On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > 
> > > > Heya,
> 
> > > > I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > > > I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> 
> > > > Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> 
> > > > -shay.banon
> 
> > > > On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> > > > 
> > > > > the problem does not occur for
> 
> > > > > put("index.number\_of\_shards", 1)
> 
> > > > > but does for shards\>1
> 
> > > > > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > > > > 
> > > > > > Hi,
> 
> > > > > > I simply want a functionality to reindex my docs currently indexed.  
> > > > > > Has someone some code for this 🙂 ?
> 
> > > > > > There is a problem either in my code or in ES when doing some  
> > > > > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > > > > box runnable gist:
> 
> > > > > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> 
> > > > > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > > > > documents returned???
> 
> > > > > > Regards,  
> > > > > > Peter.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 9, 2011, 7:36pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/8 "2011-02-09T19:36:08Z")

</div>

Yes, memory (at least the priority queue used by lucene) will be done for 0...B. The scan type will be without scoring, yes, and mainly aimed at things like scanning all the hits that match a specific query.

I am not sure about why it works without specifying hte index and when you do. It does not matter when working with a single index. A good place to start in order to solve it is to take your code and make it a test case in ES that recreates it. Check SearchScrollTests in the integration module, you can add a test there.

-shay.banon  
On Wednesday, February 9, 2011 at 8:47 PM, Karussell wrote:

> hmmh, when I'm doing an 'implicit search' (\_all??) it works correctly:
> 
> // for (String fromIndex : indexList) {  
> String fromIndex = "";  
> SearchResponse rsp = client.prepareSearch().  
> ...
> 
> On 9 Feb., 18:06, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> 
> > Hi Shay,
> > 
> > thanks for your answers! Do you know where the flaw could come from? I  
> > would like to investigate/fix it as I'm unsure if reindexing works  
> > even with this flaw ...
> > 
> > > you will have the same problem with search and doing pagination using from / size
> > 
> > Does it mean that if I want docs from pages A..B then ES has to use  
> > memory for 0..B ?
> > 
> > Could I overcome this problem with additional filter queries if I know  
> > how to split up my data - e.g. based on date?
> > 
> > Would the scan type be without scoring (I don't need that)?
> > 
> > Regards,  
> > Peter.
> > 
> > On 8 Feb., 23:23, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > On Wednesday, February 9, 2011 at 12:07 AM, Karussell wrote:
> > 
> > > So, in your case, create and add it directly to a BulkRequestBuilder.
> > 
> > > > ok. what's so expensive to create that jsonBuilder?
> > 
> > > Its not a question of expensive, but the byte buffer that is behind it is being reused on a thread local to reduce byte copying.
> > 
> > > > > safeJsonBuilder
> > 
> > > > do you mean?  
> > > > XContentBuilder docBuilder =  
> > > > JsonXContent.unCachedContentBuilder().startObject();
> > 
> > > Yea, that is there as well. I added safeJsonBuilder that delegates to that one.
> > 
> > > > > Also, scrolling is not the best way to reindex the data
> > 
> > > > so, how would you do this at the moment. would you use simple search  
> > > > (e.g. with a date filter) instead scrolling?
> > 
> > > You will have the same problem with search and doing pagination using from / size. Thats why the scan type is needed. The overhead does not come from the scrolling implementation, but from how search is executed when it needs to do a sort in lucene, and when its distributed.
> > 
> > > > Regards,  
> > > > Peter.
> > 
> > > > On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > > 
> > > > > Heya,
> > 
> > > > > I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> > 
> > > > > I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> > 
> > > > > Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> > 
> > > > > -shay.banon
> > 
> > > > > On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> > > > > 
> > > > > > the problem does not occur for
> > 
> > > > > > put("index.number\_of\_shards", 1)
> > 
> > > > > > but does for shards\>1
> > 
> > > > > > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > > > > > 
> > > > > > > Hi,
> > 
> > > > > > > I simply want a functionality to reindex my docs currently indexed.  
> > > > > > > Has someone some code for this 🙂 ?
> > 
> > > > > > > There is a problem either in my code or in ES when doing some  
> > > > > > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > > > > > box runnable gist:
> > 
> > > > > > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> > 
> > > > > > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > > > > > documents returned???
> > 
> > > > > > > Regards,  
> > > > > > > Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 9, 2011, 8:47pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/9 "2011-02-09T20:47:17Z")

</div>

I opened this issue:

> <https://github.com/elastic/elasticsearch/issues/680>
>
> As discussed under:
> 
> http://groups.google.com/a/elasticsearch.com/group/users/br…owse\_thread/thread/5c93b640dee0dfd3
> 
> the following integration test can reproduce this behaviour:
> 
> https://gist.github.com/819239
> 
> Again when I don't specify the index in prepareSearch it works, it also works for shards==1, it also works if id is NOT in the range of the second bulkUpdate.
> 
> Hope I did not something completly stupid :/

with the integration test - still failing:

> <https://gist.github.com/karussell/819239>

On 9 Feb., 20:36, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Yes, memory (at least the priority queue used by lucene) will be done for 0...B. The scan type will be without scoring, yes, and mainly aimed at things like scanning all the hits that match a specific query.
> 
> I am not sure about why it works without specifying hte index and when you do. It does not matter when working with a single index. A good place to start in order to solve it is to take your code and make it a test case in ES that recreates it. Check SearchScrollTests in the integration module, you can add a test there.
> 
> -shay.banon
> 
> On Wednesday, February 9, 2011 at 8:47 PM, Karussell wrote:
> 
> > hmmh, when I'm doing an 'implicit search' (\_all??) it works correctly:
> 
> > // for (String fromIndex : indexList) {  
> > String fromIndex = "";  
> > SearchResponse rsp = client.prepareSearch().  
> > ...
> 
> > On 9 Feb., 18:06, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > 
> > > Hi Shay,
> 
> > > thanks for your answers! Do you know where the flaw could come from? I  
> > > would like to investigate/fix it as I'm unsure if reindexing works  
> > > even with this flaw ...
> 
> > > > you will have the same problem with search and doing pagination using from / size
> 
> > > Does it mean that if I want docs from pages A..B then ES has to use  
> > > memory for 0..B ?
> 
> > > Could I overcome this problem with additional filter queries if I know  
> > > how to split up my data - e.g. based on date?
> 
> > > Would the scan type be without scoring (I don't need that)?
> 
> > > Regards,  
> > > Peter.
> 
> > > On 8 Feb., 23:23, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > > > On Wednesday, February 9, 2011 at 12:07 AM, Karussell wrote:
> 
> > > > So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > > > > ok. what's so expensive to create that jsonBuilder?
> 
> > > > Its not a question of expensive, but the byte buffer that is behind it is being reused on a thread local to reduce byte copying.
> 
> > > > > > safeJsonBuilder
> 
> > > > > do you mean?  
> > > > > XContentBuilder docBuilder =  
> > > > > JsonXContent.unCachedContentBuilder().startObject();
> 
> > > > Yea, that is there as well. I added safeJsonBuilder that delegates to that one.
> 
> > > > > > Also, scrolling is not the best way to reindex the data
> 
> > > > > so, how would you do this at the moment. would you use simple search  
> > > > > (e.g. with a date filter) instead scrolling?
> 
> > > > You will have the same problem with search and doing pagination using from / size. Thats why the scan type is needed. The overhead does not come from the scrolling implementation, but from how search is executed when it needs to do a sort in lucene, and when its distributed.
> 
> > > > > Regards,  
> > > > > Peter.
> 
> > > > > On 8 Feb., 22:44, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > > > > 
> > > > > > Heya,
> 
> > > > > > I will have a look. A note on your usage of XContentBuilder, when using XContentFactory#jsonBuilder, a cached version is returned, and it is expected that you will pass hte result to an API before you call it again on the same thread. So, in your case, create and add it directly to a BulkRequestBuilder.
> 
> > > > > > I have just added safeJsonBuilder which will return one that is not cached per thread, but you should use the above.
> 
> > > > > > Also, scrolling is not the best way to reindex the data, as it can get pretty expensive as you page through the hit list. I am planning to add a "scan" type search that will not incur this overhead (but will also do no sorting).
> 
> > > > > > -shay.banon
> 
> > > > > > On Tuesday, February 8, 2011 at 10:29 PM, Karussell wrote:
> > > > > > 
> > > > > > > the problem does not occur for
> 
> > > > > > > put("index.number\_of\_shards", 1)
> 
> > > > > > > but does for shards\>1
> 
> > > > > > > On 8 Feb., 21:27, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:
> > > > > > > 
> > > > > > > > Hi,
> 
> > > > > > > > I simply want a functionality to reindex my docs currently indexed.  
> > > > > > > > Has someone some code for this 🙂 ?
> 
> > > > > > > > There is a problem either in my code or in ES when doing some  
> > > > > > > > 'overwriting' updates and then scrolling. Please see this out-of-the-  
> > > > > > > > box runnable gist:
> 
> > > > > > > > [Something goes wrong when doing bulkUpdate and retrieving · GitHub](https://gist.github.com/817094)
> 
> > > > > > > > Look at 'showStrangeBehaviour' and set it to true. Why are not all 200  
> > > > > > > > documents returned???
> 
> > > > > > > > Regards,  
> > > > > > > > Peter.

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 9, 2011, 9:35pm UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/10 "2011-02-09T21:35:19Z")

</div>

ok, found workaround/fix. see issue

---

<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:** [July 6, 2017, 4:12am UTC](https://discuss.elastic.co/t/bug-when-scrolling/3901/11 "2017-07-06T04:12:16Z")

</div>


