# IndexMissingException on create index followed by refresh

**URL:** <https://discuss.elastic.co/t/indexmissingexception-on-create-index-followed-by-refresh/3505>\
**Category:** Elasticsearch\
**Created:** [November 3, 2010, 4:52am UTC](https://discuss.elastic.co/t/indexmissingexception-on-create-index-followed-by-refresh/3505 "2010-11-03T04:52:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Gavarini](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sebastian\_Gavarini](https://discuss.elastic.co/u/Sebastian_Gavarini)\
**Post date:** [November 3, 2010, 4:52am UTC](https://discuss.elastic.co/t/indexmissingexception-on-create-index-followed-by-refresh/3505/1 "2010-11-03T04:52:27Z")

</div>

Hi, I am seeing an IndexMissingException when I do an index create  
followed immediately by refresh.

first of all, my setup is:

- ES 0.12.1
- Java client API, embedded no-data node
- local gateway
- remote ES data node

My pseudocode goes like this:

- create index (1 shard, 0 replica for batch indexing)
- add documents if any
- refresh
- flush
- optimize  
...  
In my first attempt I didn't have documents in my DB, so create was  
followed by refresh without delay, in that case I am seeing:

Exception in thread "Thread-6"  
org.elasticsearch.indices.IndexMissingException: [index-dev-v0]  
missing  
at  
org.elasticsearch.cluster.routing.RoutingTable.allShardsGrouped(RoutingTable.java:  
153)  
at  
org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction.shards(TransportRefreshAction.java:  
116)  
at  
org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction.shards(TransportRefreshAction.java:  
50)  
at  
org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction  
$AsyncBroadcastAction.(TransportBroadcastOperationAction.java:  
161)  
at  
org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction.doExecute(TransportBroadcastOperationAction.java:  
77)  
at  
org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction.doExecute(TransportBroadcastOperationAction.java:  
54)  
at  
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:  
54)  
at  
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:  
43)  
at  
org.elasticsearch.client.node.NodeIndicesAdminClient.refresh(NodeIndicesAdminClient.java:  
147)

When I call create index I wait for the future to finish with:  
CreateIndexResponse response = future.actionGet();  
When using "curl" to the remote ES node I can see the index is in fact  
created, contrary to the exception.

If I add a 100ms delay in the "add documents" step everything works  
OK, that's why I think it must be a concurrency issue, locking bug or  
the like.

I understand that creating an index and then refreshing it is  
pointless, I expect "add documents" to actually add some, but in this  
case the DB was still empty and this weird thing happened. I could add  
some checks in my code for that case, but I think it must be a tiny  
bug that's better tackled. I could help with more details or tests if  
somebody wishes to trace the problem.

Thanks,  
Sebastian.

---

<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:** [November 3, 2010, 2:24pm UTC](https://discuss.elastic.co/t/indexmissingexception-on-create-index-followed-by-refresh/3505/2 "2010-11-03T14:24:20Z")

</div>

Hi,

Let me explain why this happens. When creating an index, the creation  
itself happens on the master node, and the fact that it gets created is  
published to all the other nodes (including the client node). If you try and  
do a refresh right after, the fact that the index was created might not have  
gotten to the client node you are working with. The create index does wait  
for all the changes to be sent to the clients, but not for it to be applied.

```
Some operation do wait for an index if it has not been created, like

```

index and delete, as they have timeouts. Others, like get / refresh do not  
(as it make little sense for them to wait, the index name might be wrong).

```
You can try and explicitly create the index, and then wait using the

```

cluster health API for at least a yellow status. Its usually a good practice  
(your recovery might take time).

```
Its something that needs to be solved. Not that simple because of its

```

distributed nature. I have some ideas on how to solve it without causing to  
much load on the cluster... .

-shay.banon

On Wed, Nov 3, 2010 at 6:52 AM, Sebastian [sgavarini@gmail.com](mailto:sgavarini@gmail.com) wrote:

> Hi, I am seeing an IndexMissingException when I do an index create  
> followed immediately by refresh.
> 
> first of all, my setup is:
> 
> - ES 0.12.1
> - Java client API, embedded no-data node
> - local gateway
> - remote ES data node
> 
> My pseudocode goes like this:
> 
> - create index (1 shard, 0 replica for batch indexing)
> - add documents if any
> - refresh
> - flush
> - optimize  
> ...  
> In my first attempt I didn't have documents in my DB, so create was  
> followed by refresh without delay, in that case I am seeing:
> 
> Exception in thread "Thread-6"  
> org.elasticsearch.indices.IndexMissingException: [index-dev-v0]  
> missing  
> at
> 
> org.elasticsearch.cluster.routing.RoutingTable.allShardsGrouped(RoutingTable.java:  
> 153)  
> at
> 
> org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction.shards(TransportRefreshAction.java:  
> 116)  
> at
> 
> org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction.shards(TransportRefreshAction.java:  
> 50)  
> at
> 
> org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction  
> $AsyncBroadcastAction.(TransportBroadcastOperationAction.java:  
> 161)  
> at
> 
> org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction.doExecute(TransportBroadcastOperationAction.java:  
> 77)  
> at
> 
> org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction.doExecute(TransportBroadcastOperationAction.java:  
> 54)  
> at  
> org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:  
> 54)  
> at  
> org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:  
> 43)  
> at
> 
> org.elasticsearch.client.node.NodeIndicesAdminClient.refresh(NodeIndicesAdminClient.java:  
> 147)
> 
> When I call create index I wait for the future to finish with:  
> CreateIndexResponse response = future.actionGet();  
> When using "curl" to the remote ES node I can see the index is in fact  
> created, contrary to the exception.
> 
> If I add a 100ms delay in the "add documents" step everything works  
> OK, that's why I think it must be a concurrency issue, locking bug or  
> the like.
> 
> I understand that creating an index and then refreshing it is  
> pointless, I expect "add documents" to actually add some, but in this  
> case the DB was still empty and this weird thing happened. I could add  
> some checks in my code for that case, but I think it must be a tiny  
> bug that's better tackled. I could help with more details or tests if  
> somebody wishes to trace the problem.
> 
> Thanks,  
> Sebastian.

---

<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:17am UTC](https://discuss.elastic.co/t/indexmissingexception-on-create-index-followed-by-refresh/3505/3 "2017-07-06T04:17:13Z")

</div>


