# Trying to force merge index

**URL:** https://discuss.elastic.co/t/trying-to-force-merge-index/133209
**Category:** Elasticsearch
**Created:** [May 24, 2018, 6:23pm UTC](https://discuss.elastic.co/t/trying-to-force-merge-index/133209 "2018-05-24T18:23:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rah](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@Rah](https://discuss.elastic.co/u/Rah)
#### Post date: [May 24, 2018, 6:23pm UTC](https://discuss.elastic.co/t/trying-to-force-merge-index/133209/1 "2018-05-24T18:23:23Z")

</div>

Hi,

I am trying to force purge document immediately after deleting . I am unable to perform it without full re-indexing.  
I deleted 3 document in total of 10, but the total document in ES still shows 10.  
Following are the result of various api calls :  
**\_stats** --\>  
"indexing": {  
"index\_total": 22,  
"index\_time\_in\_millis": 445,  
"index\_current": 0,  
"index\_failed": 68,  
"delete\_total": 3,  
"delete\_time\_in\_millis": 2,

I am invoking forcemerge in following way :  
private void optimizeIndex(String index, int maxNumSegments) {  
Client client = (Client)SpringUtil.getBean("searchClient");  
final ForceMergeRequest request = client.admin().indices().prepareForceMerge(index).setMaxNumSegments(maxNumSegments).setOnlyExpungeDeletes(true).setFlush(true).request();

```
        // Using a specific timeout to override the global Elasticsearch request timeout
        ForceMergeResponse forceMergeResponse = client.admin().indices().forceMerge(request).actionGet();
}

```

I am calling this function as soon as I delete documents.  
Not sure what I am doing wrong.

Thanks,  
RAH

---

<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: [May 26, 2018, 5:49am UTC](https://discuss.elastic.co/t/trying-to-force-merge-index/133209/2 "2018-05-26T05:49:34Z")

</div>

Did you run a refresh before running the forcemerge?

---

<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: [June 23, 2018, 5:49am UTC](https://discuss.elastic.co/t/trying-to-force-merge-index/133209/3 "2018-06-23T05:49:47Z")

</div>

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