# Clearing the search context manually after reindexing is done

**URL:** <https://discuss.elastic.co/t/clearing-the-search-context-manually-after-reindexing-is-done/346517>\
**Category:** Elasticsearch\
**Created:** [November 6, 2023, 11:28am UTC](https://discuss.elastic.co/t/clearing-the-search-context-manually-after-reindexing-is-done/346517 "2023-11-06T11:28:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Achyut\_Muley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/achyut_muley/32/122260_2.png) [@Achyut\_Muley](https://discuss.elastic.co/u/Achyut_Muley)\
**Post date:** [November 6, 2023, 11:28am UTC](https://discuss.elastic.co/t/clearing-the-search-context-manually-after-reindexing-is-done/346517/1 "2023-11-06T11:28:36Z")

</div>

We have a shell script which takes the name of an index and then reindexes it.  
We are using ES 7.17.0  
The reindex command-

`response=$(curl -u $CREDENTIALS -X POST "$PROTOCOL://$HOST:9200/_reindex?slices=50&refresh&wait_for_completion=false" -H "Content-Type: application/json" -d "{ \"source\": { \"index\": \"$INDEX\",\"size\":5}, \"dest\": { \"index\": \"$new_index\" } }" --write-out '%{http_code}')`

Here we are using slice and size as well.But i was getting the search context missing exception and es was complaining that no search context is found for most of the slices.  
The index is big and has a lot of docs.I figured out that search context expires in 5 min.Hence i am giving scroll=1h in the reindex call

But there are many indices for which it might take even more time.So instead of hardcoding it everytime i was thinking of giving it as scroll=2d  
I guess this might slow down the performance of Elasticsearch as if the reindexing is completed soon,still search context will be active..

I am thinking of using the following approach-  
Make scroll=2d and then if the reindexing is complete anytime sooner than clear the search context using this api-

```auto
 DELETE /_search/scroll
 {
   "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ=="
 }

```

Will this approach work and is this the correct approach?  
I am a bit skeptical because till now we have not been touching the search context explicitly and i want to make sure clearing this doesn't lead to any other error..  
Also should i use size as auto instead of a manual number?  
Any other approach to solve this issue is welcome.

---

<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:** [December 4, 2023, 11:29am UTC](https://discuss.elastic.co/t/clearing-the-search-context-manually-after-reindexing-is-done/346517/2 "2023-12-04T11:29:31Z")

</div>

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